05.配置为开发模式、配置静态资源locations、自定义消息转化器、FastJson
配置为开发模式,代码做了修改,不用重新运行 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的更多相关文章
- springboot(四).配置FastJson自定义消息转化器
配置FastJson自定义消息转化器 一.fastJson简介 fastJson是阿里巴巴旗下的一个开源项目之一,顾名思义它专门用来做快速操作Json的序列化与反序列化的组件.它是目前json解析最快 ...
- Spring Mvc Web 配置拦截规则与访问静态资源 (三)
拦截规则配置 1. *.do <!-- Processes application requests --> <servlet> <servlet-name>app ...
- webpack中devtool的配置方案[开发模式]---[线上模式]
// 开发模式下 module.exports = { mode: 'development', devtool: 'cheap-module-eval-source-map' } // 线上模式下 ...
- 动态script标签同步加载 ps:无打包编译,静态实现静态资源入口动态配置,无编译打包静态资源添加版本号
/**功能:创建动态标签加载css ,js文件,重点是js文件,利用onloading加递归实现动态标签的同步加载用法:在html文件body底部script内部声明并调用下列函数,obj中写要加载的 ...
- Go语言配置与开发环境配置
1.首先下载go的运行时 http://golang.org/dl/ 下载windows 的zip版本,解压到硬盘上的一个位置 2.设置环境变量如下 GOBIN %GOROOT%\bin //go的 ...
- 【spring boot】7.静态资源和拦截器处理 以及继承WebMvcConfigurerAdapter类进行更多自定义配置
开头是鸡蛋,后面全靠编!!! ======================================================== 1.默认静态资源映射路径以及优先顺序 Spring B ...
- SpringBoot 配置静态资源映射
SpringBoot 配置静态资源映射 (嵌入式servlet容器)先决知识 request.getSession().getServletContext().getRealPath("/& ...
- springboot配置静态资源访问路径
其实在springboot中静态资源的映射文件是在resources目录下的static文件夹,springboot推荐我们将静态资源放在static文件夹下,因为默认配置就是classpath:/s ...
- webpack4使用mode优化开发环境配置
@subject: webpack mode @author: leinov @date: 2018-11-29 mode webpack的 mode 配置用于提供模式配置选项告诉webpack相应地 ...
随机推荐
- [luogu]P1169 [ZJOI2007]棋盘制作[DP][单调栈]
[luogu]P1169 [ZJOI]棋盘制作 ——!x^n+y^n=z^n 题目描述 国际象棋是世界上最古老的博弈游戏之一,和中国的围棋.象棋以及日本的将棋同享盛名.据说国际象棋起源于易经的思想,棋 ...
- 特权第一讲--Lesson 1 课程概述与如何学好FPGA
FPGA的学习没有什么捷径,需要学习者多花时间和精力 . 1.设计输入 2.如何--对综合布局布线结果进行优化 3.如何--更有效地进行验证 4.如何--达到时序收敛 学习者需要用心去学习.去分析.去 ...
- Maven安装本地jar包至本地repository
1.安装jar包 Maven 安装 JAR 包的命令是: mvn install:install-file -Dfile=jar包的位置 -DgroupId=上面的groupId -Dartifa ...
- FCC 成都社区·前端周刊 第 10 期
1. Node.js 10 正式发布 在过去的一周,Node.js 10.0.0 正式发布,带来大量改进和修复.这是自 Node.js Foundation 开展以来的第七个主要版本,并将在 2018 ...
- Linux shell - scp命令用法
例子: 远程复制一个文件从服务器A (172.0.0.0) /home/test/file1.txt 到 服务器B (172.0.0.1) /home/test 服务器A和服务器B的用户是 test ...
- C# 高性能 TCP 服务的多种实现方式Cowboy.Sockets
本篇文章的主旨是使用 .NET/C# 实现 TCP 高性能服务的不同方式,包括但不限于如下内容: APM 方式,即 Asynchronous Programming Model TAP 方式,即 ...
- canvas绘制小人开口和闭口
css: <style> body{ text-align: center; } canvas{ background: #ddd; } </style>canvas标签:&l ...
- JS对象—字符串总结(创建、属性、方法)
1.创建字符串 1.1 new String(s) String和new一起使用,创建的是一个字符串对象,存放的是字符串s的表示. 1.2 String(s) ...
- 【洛谷p2089】 烤鸡
烤鸡[题目链接] 感觉我超废 关于算法:有很多很多算法吧,但自我感觉最重要的是递归的算法: SOLUTION: 首先忍不住要吐槽这个神仙数据: 嗯???定睛一看,它这数据范围莫不是白瞎了,因为每种配料 ...
- 运输计划(题解)(Noip2015)
运输计划(题解)(Noip2015) 二分答案+树上差分 树上差分其实不难,只是名字高大尚,可以学一下:Eternal风度的树上差分 本人博客里也总结了一些其他的知识供大家学习:Eternal风度的博 ...