SpringBoot的其他配置(SpringBoot项目配置4)

1.SpringBoot的编码格式、文件上传大小设置

在application.xml文件中加入如下内容:

spring:
  http:
    encoding:
      charset: UTF-8
      force: true
    multipart:
      max-file-size: 100MB

2.FastJSON

在pom.xml中加入下面的内容

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

在入口类中加入

@Bean
public HttpMessageConverters fastjsonHttpMessageConverter(){
//定义一个转换消息的对象
FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter();
//添加fastjson的配置信息 比如 :是否要格式化返回的json数据
FastJsonConfig fastJsonConfig = new FastJsonConfig();
fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat);
//在转换器中添加配置信息
fastConverter.setFastJsonConfig(fastJsonConfig);
HttpMessageConverter<?> converter = fastConverter;
return new HttpMessageConverters(converter);
}

 3.web项目热部署配置

为了不频繁的创建启动SpringBoot程序,SpringBoot自身提供了热部署支持

(1)引入springboot的热部署jar包

在pom.xml中加入下面的内容

<dependency>
          <groupId>org.springframework</groupId>
          <artifactId>springloaded</artifactId>
          <version>1.2.7.RELEASE</version>
</dependency>

(2)开启IDEA的自动编译功能

(3)Ctrl+Shift+Alt+/ 勾选running

(4)开启jsp页面自动修改后自动更新

猜你喜欢

转载自www.cnblogs.com/henuLiGang/p/9256843.html