最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

springboot實(shí)現(xiàn)FastJson解析json數(shù)據(jù)的方法

 更新時(shí)間:2017年04月28日 15:34:43   作者:ZhangJQKb  
本篇文章主要介紹了springboot實(shí)現(xiàn)FastJson解析json數(shù)據(jù)的方法,非常具有實(shí)用價(jià)值,需要的朋友可以參考下

最近在研究springboot實(shí)現(xiàn)FastJson解析json數(shù)據(jù)的方法,那么今天也算個(gè)學(xué)習(xí)筆記吧!

添加jar包:

<dependency> 
      <groupId>com.alibaba</groupId> 
      <artifactId>fastjson</artifactId> 
      <version>1.2.15</version> 
  </dependency> 

兩種方式啟動(dòng)加載類:

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

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:

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:

@JSONField(serialize=false) 
private Long id; 

返回前端就會(huì)沒有id這個(gè)屬性值

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Java實(shí)現(xiàn)分布式系統(tǒng)限流

    Java實(shí)現(xiàn)分布式系統(tǒng)限流

    這篇文章主要為大家詳細(xì)介紹了Java實(shí)現(xiàn)分布式系統(tǒng)限流,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-08-08
  • 解決dubbo注冊(cè)到zookeeper速度慢的問題

    解決dubbo注冊(cè)到zookeeper速度慢的問題

    這篇文章主要介紹了解決dubbo注冊(cè)到zookeeper速度慢的問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-04-04
  • Java 8 新特性終極版指南詳解

    Java 8 新特性終極版指南詳解

    Java 8已經(jīng)公布有一段時(shí)間了,種種跡象表明Java 8是一個(gè)有重大改變的發(fā)行版。本文給大家介紹Java 8 新特性終極版指南詳解,需要的朋友參考下
    2016-03-03
  • Java?Spring的使用注解開發(fā)詳解

    Java?Spring的使用注解開發(fā)詳解

    這篇文章主要為大家介紹了Java?Spring注解開發(fā),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來幫助
    2022-01-01
  • 解析ConcurrentHashMap: 預(yù)熱(內(nèi)部一些小方法分析)

    解析ConcurrentHashMap: 預(yù)熱(內(nèi)部一些小方法分析)

    ConcurrentHashMap是由Segment數(shù)組結(jié)構(gòu)和HashEntry數(shù)組結(jié)構(gòu)組成。Segment的結(jié)構(gòu)和HashMap類似,是一種數(shù)組和鏈表結(jié)構(gòu),今天給大家普及java面試常見問題---ConcurrentHashMap知識(shí),一起看看吧
    2021-06-06
  • ocp開閉原則_動(dòng)力節(jié)點(diǎn)Java學(xué)院整理

    ocp開閉原則_動(dòng)力節(jié)點(diǎn)Java學(xué)院整理

    這篇文章主要為大家詳細(xì)介紹了ocp開閉原則的相關(guān)資料,ocp開閉原則指導(dǎo)我們?nèi)绾谓⒁粋€(gè)穩(wěn)定的、靈活的系統(tǒng),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-08-08
  • JHipster如何修改JDL中的entity

    JHipster如何修改JDL中的entity

    這篇文章主要介紹了JHipster如何修改JDL中的entity問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-11-11
  • Spring Boot動(dòng)態(tài)加載Jar包與動(dòng)態(tài)配置實(shí)現(xiàn)

    Spring Boot動(dòng)態(tài)加載Jar包與動(dòng)態(tài)配置實(shí)現(xiàn)

    隨著項(xiàng)目的不斷演進(jìn)和業(yè)務(wù)需求的增長,很多場景下需要實(shí)現(xiàn)系統(tǒng)的動(dòng)態(tài)性和靈活性,本文主要介紹了Spring Boot動(dòng)態(tài)加載Jar包與動(dòng)態(tài)配置實(shí)現(xiàn),具有一定的參考價(jià)值,感興趣的可以了解一下
    2024-02-02
  • Java 程序內(nèi)部是如何執(zhí)行的?

    Java 程序內(nèi)部是如何執(zhí)行的?

    這篇文章主要介紹了Java 程序內(nèi)部是如何執(zhí)行的,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-07-07
  • Mybatis源碼解析之mapper接口的代理模式詳解

    Mybatis源碼解析之mapper接口的代理模式詳解

    這篇文章主要介紹了Mybatis源碼解析之mapper接口的代理模式詳解,在mybatis中執(zhí)行sql時(shí)有兩種方式,一種是基于statementId,也就是直接調(diào)用SqlSession的方法,需要的朋友可以參考下
    2023-12-12

最新評(píng)論

尖扎县| 牡丹江市| 长武县| 成武县| 泸西县| 米易县| 十堰市| 稷山县| 班戈县| 革吉县| 泗水县| 台中县| 大丰市| 忻城县| 灵石县| 拉萨市| 贵港市| 湖北省| 东乌| 绥芬河市| 留坝县| 疏勒县| 城市| 西城区| 大埔县| 山阴县| 永嘉县| 武胜县| 福州市| 章丘市| 舟山市| 林甸县| 保德县| 如东县| 收藏| 钟山县| 根河市| 合江县| 进贤县| 中西区| 新丰县|