配置为开发模式,代码做了修改,不用重新运行 idea需要该配置,mac测试无效

 <dependency>
<groupId>org.springframework</groupId>
<artifactId>springloaded</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>

访问静态资源

src/main/resources/static

# 设定静态文件路径
spring.resources.static-locations=classpath:/static/

自定义消息转化器

    //定义消息转换器
//springboot默认配置org.springframework.boot.autoconfigure.web.HttpMessageConvertersAutoConfiguration
@Bean
public StringHttpMessageConverter stringHttpMessageConverter(){
return new StringHttpMessageConverter(StandardCharsets.ISO_8859_1);
}
@RequestMapping("/")
public String first(){
return "hello傅立叶" //因为使用的是ISO_8859_1,所以中文乱码
}

idea读取properties文件中的汉字乱码解决

在IntelliJ IDEA中依次点击File -> Settings -> Editor -> File Encodings 全部设置UTF-8,Transparent native-to-ascii 打勾

create UTF-8 files选择with NO BOM

FastJson

springboot默认使用的是Jackson

<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.15</version>
</dependency>
@SpringBootApplication(scanBasePackages = {"com.fly"})//默认是本包及子报
public class SpringDemoApp extends WebMvcConfigurerAdapter { @Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
//创建FastJson的消息转换器
FastJsonHttpMessageConverter converter = new FastJsonHttpMessageConverter();
//创建FastJson的配置对象
FastJsonConfig config = new FastJsonConfig();
//对Json数据进行格式化
config.setSerializerFeatures(SerializerFeature.PrettyFormat);
converter.setFastJsonConfig(config);
converters.add(converter);
} //不继承WebMvcConfigurerAdapter使用配置成Bean的方式
//@Bean
//public HttpMessageConverters fastJsonHttpMessageConverter(){
// //创建FastJson的消息转换器
// FastJsonHttpMessageConverter converter = new FastJsonHttpMessageConverter();
// //创建FastJson的配置对象
// FastJsonConfig config = new FastJsonConfig();
// //对Json数据进行格式化
// config.setSerializerFeatures(SerializerFeature.PrettyFormat);
// converter.setFastJsonConfig(config);
// return new HttpMessageConverters(converter);
//} public static void main(String[] args){
SpringApplication.run(SpringDemoApp.class,args);
}
}
    @RequestMapping("/person")
public Object show(){
Person person = new Person();
person.setId(1);
person.setDate(new Date());
person.setName("fly傅立叶");
return person;
}

发现中文乱码了

#response编码设置为utf-8功能开启
spring.http.encoding.force=true

**时间显示的是时间戳

  @JSONField(format = "yyyy-MM-dd HH:mm:ss") //也可以加在字段上
public Date getDate() {
return date;
}

05.配置为开发模式、配置静态资源locations、自定义消息转化器、FastJson的更多相关文章

  1. springboot(四).配置FastJson自定义消息转化器

    配置FastJson自定义消息转化器 一.fastJson简介 fastJson是阿里巴巴旗下的一个开源项目之一,顾名思义它专门用来做快速操作Json的序列化与反序列化的组件.它是目前json解析最快 ...

  2. Spring Mvc Web 配置拦截规则与访问静态资源 (三)

    拦截规则配置 1. *.do <!-- Processes application requests --> <servlet> <servlet-name>app ...

  3. webpack中devtool的配置方案[开发模式]---[线上模式]

    // 开发模式下 module.exports = { mode: 'development', devtool: 'cheap-module-eval-source-map' } // 线上模式下 ...

  4. 动态script标签同步加载 ps:无打包编译,静态实现静态资源入口动态配置,无编译打包静态资源添加版本号

    /**功能:创建动态标签加载css ,js文件,重点是js文件,利用onloading加递归实现动态标签的同步加载用法:在html文件body底部script内部声明并调用下列函数,obj中写要加载的 ...

  5. Go语言配置与开发环境配置

    1.首先下载go的运行时 http://golang.org/dl/  下载windows 的zip版本,解压到硬盘上的一个位置 2.设置环境变量如下 GOBIN %GOROOT%\bin //go的 ...

  6. 【spring boot】7.静态资源和拦截器处理 以及继承WebMvcConfigurerAdapter类进行更多自定义配置

    开头是鸡蛋,后面全靠编!!! ========================================================  1.默认静态资源映射路径以及优先顺序 Spring B ...

  7. SpringBoot 配置静态资源映射

    SpringBoot 配置静态资源映射 (嵌入式servlet容器)先决知识 request.getSession().getServletContext().getRealPath("/& ...

  8. springboot配置静态资源访问路径

    其实在springboot中静态资源的映射文件是在resources目录下的static文件夹,springboot推荐我们将静态资源放在static文件夹下,因为默认配置就是classpath:/s ...

  9. webpack4使用mode优化开发环境配置

    @subject: webpack mode @author: leinov @date: 2018-11-29 mode webpack的 mode 配置用于提供模式配置选项告诉webpack相应地 ...

随机推荐

  1. 【テンプレート】RMQ

    1174 区间中最大的数 基准时间限制:1 秒 空间限制:131072 KB   收藏  关注 给出一个有N个数的序列,编号0 - N - 1.进行Q次查询,查询编号i至j的所有数中,最大的数是多少. ...

  2. Linux CentOS7 安装docker

    Docker 是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的容器中,然后发布到任何流行的Linux机器上,也可以实现虚拟化,容器是完全使用沙箱机制,相互之间不会有任何接口 ...

  3. eclipse 4.5 离线安装mybatis generator1.3.6卡在Install New Software的解决方法

    转载:https://blog.csdn.net/ssshen14/article/details/80004459 离线插件 下载:https://github.com/mybatis/genera ...

  4. 学习日记7、mvc +easyui datagrid excel上传

    1.首先获取datagrid所有行的数据 var rows = $("#List").datagrid("getRows"); 2.进行数据转换转化成JSON格 ...

  5. elasticsearch 集群搭建及启动常见错误

    1.系统环境 三台服务器(最好是单数台,跟master选举方式有关),确保机器互相ping的通,且都需要装了jdk 8环境,机器IP和 elasticsearch 的节点名称如下: cluster n ...

  6. 备份mysql的shell

    • #!/bin/bash• file_name=`date +%Y%m%d%H%M%S`• db_path='/usr/local/db_back/'• mysqldump -ulepus -p12 ...

  7. 拒绝从入门到放弃_《Openstack 设计与实现》必读目录

    目录 目录 关于这本书 必看知识点 最后 关于这本书 <Openstack 设计与实现>是一本非常值得推荐的书,为数不多的 Openstack 开发向中文书籍中的精品.如果希望从事 Ope ...

  8. Visual Studio Code配置技巧

    Visual Studio Code配置技巧 VS Code是啥 Visual Studio Code(以下简称 VS Code) 是一个免费.开源.跨平台的由微软开发的程序编辑器.它是用 TypeS ...

  9. 微信小程序这一块(下)

    1.小程序分为两部分 :页面.组件 2.小程序中如何定义自定义组件? 凡是通过Page创建的都是页面,而通过Components创建的都是组件 当组件创建成功后,在需要使用的页面进行引入,(找到页面的 ...

  10. HashMap和布隆过滤器命中性能测试

    package datafilter; import com.google.common.base.Stopwatch; import com.google.common.hash.BloomFilt ...