one.如何配置fastjson
第一种方法:
1.启动类继承extends WebMvcConfigurerAdapter
2.覆盖方法configureMessageConverters
第二种方法注入bean
/**
* springboot启动类 使用@SpringBootApplication指定这是一个Spring Boot应用程序
* 能够启动的类,同包下和当前路径的子包
* 系统名称:
* 概要说明:
* @author dq(hasee)
* @since 2017年2月23日
*/
@SpringBootApplication
public class ApplicationFastJson extends WebMvcConfigurerAdapter{
@Override
public void configureMessageConverters(
List<HttpMessageConverter<?>> converters) {
super.configureMessageConverters(converters);
/**
* 1.需要定义一个convert转换消息的对象
* 2.创建配置信息,加入配置信息:比如是否需要格式化返回的json
* 3.converter中添加配置信息
* 4.convert添加到converters当中
*/
FastJsonHttpMessageConverter fastJsonHttpMessageConverter =
new FastJsonHttpMessageConverter();
FastJsonConfig fastJsonConfig = new FastJsonConfig();
fastJsonConfig.setSerializerFeatures(
SerializerFeature.PrettyFormat
);
fastJsonHttpMessageConverter.setFastJsonConfig(fastJsonConfig);
converters.add(fastJsonHttpMessageConverter);
}
/* @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);
}*/
public static void main(String[] args) {
/*
* 在main方法中启动程序
*/
SpringApplication.run(ApplicationFastJson.class, args);
}
}
使用fastjson可以使用一些方便的功能
日期格式转化为
@JSONField(format="yyyy-MM-dd HH:mm:ss")
private Date date;
不序列化页面不显示属性
@JSONField(serialize=false)
private String notSerilized;
two:热部署
<!-- SpringLoader plugin -->
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin </artifactId>
<dependencies>
<!--springloaded hot deploy -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>springloaded</artifactId>
<version>1.2.4.RELEASE</version>
</dependency>
</dependencies>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
<configuration>
<classifier>exec</classifier>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
两种启动方式
1.run maven build goals 键入 spring-boot:run
问题 关闭进程但是不会真正关闭,需要任务管理器关闭
2.如果使用的run as – java application的话,那么还需要做一些处理。
把spring-loader-1.2.4.RELEASE.jar下载下来,放到项目的lib目录中,然后把IDEA的run参数里VM参数设置为:
-javaagent:.\lib\springloaded-1.2.4.RELEASE.jar -noverify
然后启动就可以了,这样在run as的时候,也能进行热部署
带改变方法热部署
使用devTool:原理,使用了两个classLoader,一个加载不会改变的类,另一个加载会改变的类(restart classloader),所以加载的类少,实现较快的重启时间
修改类 保存 重启
修改配置文件 保存 重启
修改页面 保存 重启 页面会刷新
注意 project build automatically必须勾选上