配置为开发模式,代码做了修改,不用重新运行 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. [CSP-S模拟测试]:飞(fly)(数状数组+简单几何)

    题目描述 $liu\_runda$决定提高一下知识水平,于是他去请教郭神.郭神随手就给了$liu\_runda$一道神题,$liu\_runda$并不会做,于是把这个题扔到联考里给高二的做.郭神有$n ...

  2. php常见五种设计模式

    php面向对象基础知识 请点击查看 一.常见的设计模式主要有23种,根据使用目标的不同可以分为以下三大类:创建设计模式.结构设计模式.行为模式创建设计模式: (5种)用于创建对象时的设计模式.初始化对 ...

  3. jmeter 命令行运行与生成报告

    一.     使用命令行方式运行Jmeter 1.1 为什么 使用GUI方式启动jmeter,运行线程较多的测试时,会造成内存和CPU的大量消耗,导致客户机卡死. 所以正确的打开方式是在GUI模式下调 ...

  4. NOIP2011 洛谷P1315 观光公交

    题目传送门 先解释一下数组的意义: d[i]表示公交车从第i个点到第i+1个点需要的时间 pas结构体中:t表示这个乘客到公交站牌的时间,u表示起点,v表示终点 wait[i]表示公交车在第i个站点等 ...

  5. SSH 的原理和实践

    最近自己在学习使用SSH,现将自己理解的SSH原理和实践SSH的操作写成一篇博客,以供日后查看. 一.SSH是什么?为什么会出现SSH? SSH英文全称是Secure Shell,即安全外壳.首先SS ...

  6. vscode左侧文件不同颜色标识含义

    代码里的左侧颜色标识: 红色,未加入版本控制; (刚clone到本地)绿色,已经加入版本控制暂未提交; (新增部分)蓝色,加入版本控制,已提交,有改动: (修改部分)白色,加入版本控制,已提交,无改动 ...

  7. Scratch可视化的编程工具

    1.是什么? 在线编程网址 是一个编程软件,但是不涉及编程语言,是针对青少年开发的编程积木模块. 2.软件的目的是什么? 激发青少年对编程的兴趣 3.怎么用呢? 软件内部是很多积木模块,需要明白每块是 ...

  8. Mac006--swithchosts安装

    Mac006--swithchosts安装 使用brew命令安装:brew cask install switchhosts 因为mac上,网络下载无法进行安装,所以应用brew命令安装. switc ...

  9. Java数组模拟栈

    一.概述 注意:模拟战还可以用链表 二.代码 public class ArrayStack { @Test public void test() { Stack s = new Stack(5); ...

  10. Day8---Python的字典类型及操作

    字典类 1.生成方法: a.介绍: 字典是键值对的集合,键值对 : 键是数据索引的扩展 b.生成方法: 使用{}  或者  dict()  a = {'a' = 1, 'b' = 2, 'c' = 3 ...