Spring-boot

Spring Boot设置fastJSON以及热部署

注:spring-boot默认使用的json解析框架是jackson,所以底层已经将jackson框架引入,所以会自动将对象返回城json

FASTJSON:

是一个Java的语言编写的高性能,功能完善,完全请立即获取iTunes  http://json.org的标准的JSON库

一:部署:

1:的pom.xml中的配置
    引入FASTJSON库
        < dependency>

          < groupId > com.alibaba </ groupId >

          < artifactId > fastjson </ artifactId >

          <版本> 1.2.15 </版本>

            </ dependency >

二:两种方式使用FASTJSON:

第一种方法就是:
(1)启动类继承extendsWebMvcConfigurerAdapter
(2)覆盖方法configureMessageConverters
代码:
SpringBootApplication
公共类ApiCoreApp扩展WebMvcConfigurerAdapter {
 
  @覆盖
  public void configureMessageConverters(List <HttpMessageConverter <?>> converters){
      super.configureMessageConverters(转换器);
 
         FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter();
 
        FastJsonConfig fastJsonConfig = new FastJsonConfig();
        fastJsonConfig.setSerializerFeatures(
                SerializerFeature.PrettyFormat
        );
        fastConverter.setFastJsonConfig(fastJsonConfig);
 
      converters.add(fastConverter);
  }
}

第二种方法在App.java启动类中,
注入Bean:HttpMessageConverters

@豆

 公共HttpMessageConvertersfastJsonHttpMessageConverters (){

 

// 1.需要定义一个convert转换消息的对象
FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter();


// 2.添加fastJso的配置信息,比如,是否格式化返回json数据;
FastJsonConfig fastJsonConfig = new FastJsonConfig();
fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat);


// 3.在转换中添加配置信息;
fastConverter.setFastJsonConfig(fastJsonConfig);
HttpMessageConverter <?> converter = fastConverter;

// 4.将转换添加到转换中
返回新的HttpMessageConverters(转换器);

 }

三:几种FASTJSON注解

将数据返回为定义的类型

•@ JSONField(format =“yyyy-MM-dd HH:mm”)
•Datedate

是否序列化,输出不显示

•@ JSONField(连载= FALSE)
•Strngusername
################################################## ################################################## ####################################

################################################## ################################################## ####################################

热部署:

基于springboot + devtools
1:配置的pom.xml
1。
<! - spring-boot-devtools依赖包(实现热部署) - >
<依赖性>
<的groupId> org.springframework.boot </的groupId>
<artifactId的>弹簧引导devtools </ artifactId的>
<可选>真</可选>
<范围>真</范围>
</依赖性>
2。
<! - 这是spring boot devtool插件 - >
<插件>
<的groupId> org.springframework.boot </的groupId>
<artifactId的>弹簧引导行家-插件</ artifactId的>
<结构>
<! - fork:如果没有该项配置,肯定个devtools不会起作用,即应用不会重新启动 - >
<叉>真</叉>
</配置>
</插件>
2:测试
只要保存便会自动更新,不论是新建方法或者类..
3:错误原因:
•对应的弹簧引导版本是否正确,这里使用的是1.4.1版本;
•是否加入插件以及属性<叉>真</叉>
EclipseProject是否开启了BuildAutomatically(我自己就在这里栽了坑,不知道为什么我的工具什么时候关闭了自动编译的功能)。
•如果设置SpringApplication.setRegisterShutdownHook(假),则自动重启将不起作用。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值