一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

服務器之家:專注于服務器技術及軟件下載分享
分類導航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術|正則表達式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

服務器之家 - 編程語言 - Java教程 - springboot實現FastJson解析json數據的方法

springboot實現FastJson解析json數據的方法

2020-09-21 15:58ZhangJQKb Java教程

本篇文章主要介紹了springboot實現FastJson解析json數據的方法,非常具有實用價值,需要的朋友可以參考下

最近在研究springboot實現FastJson解析json數據的方法,那么今天也算個學習筆記吧!

添加jar包:

?
1
2
3
4
5
<dependency>
      <groupId>com.alibaba</groupId>
      <artifactId>fastjson</artifactId>
      <version>1.2.15</version>
  </dependency>

兩種方式啟動加載類:

第一種繼承WebMvcConfigurerAdapter,重寫configureMessageConverters方法:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.alibaba.fastjson.support.config.FastJsonConfig;
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
 
@SpringBootApplication
public class App extends WebMvcConfigurerAdapter{
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
 
@Override
public void configureMessageConverters(
List<HttpMessageConverter<?>> converters) {
// TODO Auto-generated method stub
super.configureMessageConverters(converters);
FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter();
  
    FastJsonConfig fastJsonConfig = new FastJsonConfig();
    fastJsonConfig.setSerializerFeatures(
        SerializerFeature.PrettyFormat
    );
    fastConverter.setFastJsonConfig(fastJsonConfig);
    
    converters.add(fastConverter);
 

第二種方式bean注入HttpMessageConverters:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.web.HttpMessageConverters;
import org.springframework.context.annotation.Bean;
import org.springframework.http.converter.HttpMessageConverter;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.alibaba.fastjson.support.config.FastJsonConfig;
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
 
@SpringBootApplication
public class AppTwo{
 
public static void main(String[] args) {
SpringApplication.run(AppTwo.class, args);
}
 
@Bean
public HttpMessageConverters fastJsonHttpMessageConverters() {
FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter();
FastJsonConfig fastJsonConfig = new FastJsonConfig();
fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat);
fastConverter.setFastJsonConfig(fastJsonConfig);
HttpMessageConverter<?> converter = fastConverter;
return new HttpMessageConverters(converter);
}
 
}

最后屬性前加@JSONField:

?
1
2
@JSONField(serialize=false)
private Long id;

返回前端就會沒有id這個屬性值

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持服務器之家。

原文鏈接:http://blog.csdn.net/zhangjq520/article/details/53738736

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 亚洲精品久久麻豆蜜桃 | 色综合伊人色综合网亚洲欧洲 | 国产自在自线午夜精品之la | 亚洲成av人在线视 | 国产91视频网 | 久久re热在线视频精99 | 亚洲AV午夜福利精品香蕉麻豆 | 国产福利不卡视频在免费 | 国产欧美日韩综合二区三区 | 91精品乱码一区二区三区 | 国产福利一区二区三区四区 | 欧美精选视频 | 天美蜜桃精东乌鸦传媒 | 麻豆资源 | 日韩天堂视频 | 精品视频中文字幕 | 男女男精品视频免费观看 | 97蝌蚪自拍自窝 | 92国产福利久久青青草原 | 韩国三级日本三级香港三级黄 | 女人把扒开给男人爽 | 欧美黑人一级 | 桃乃木香奈作品在线观看 | 国产精品亚洲专区一区 | 亚洲精品国偷拍自产在线观看蜜臀 | 日韩在线视频免费观看 | 欧洲久久 | 毛片一级毛片 | 我的漂亮朋友在线观看全集免费 | 色五夜婷婷 | 很黄的网站在线观看 | 成人福利在线 | 久久精品黄AA片一区二区三区 | 能播放18xxx18女同 | 国产成人综合手机在线播放 | 免费看国产精品久久久久 | 色天天色综合 | 学校捏奶揉下面污文h | 亚洲国产日韩制服在线观看 | 爆操女友 | 国产成人亚洲综合91精品555 |