配置为开发模式,代码做了修改,不用重新运行 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. 批量搞机(二):分布式ELK平台、Elasticsearch介绍、Elasticsearch集群安装、ES 插件的安装与使用

    一.分布式ELK平台 ELK的介绍: ELK 是什么? Sina.饿了么.携程.华为.美团.freewheel.畅捷通 .新浪微博.大讲台.魅族.IBM...... 这些公司都在使用 ELK!ELK! ...

  2. <自动化测试>之<自动获取手机短信验证码>

    第一次写博,最近解决了做自动化测试短信验证码自动获取填入的方法减少了脚本的人工干预,并非拦截短信,所以不存在安全警报提醒,拿出来分享给大家,有感兴趣的大家可以加Q1856100 目前在职测试开发,,写 ...

  3. ps磨皮的方法

    磨皮顾名思义就是将皮肤模糊掉,它可以去除皮肤上的一些斑点以及细纹,从而使皮肤看起来更加光滑.下面就是两张磨皮前后的对比图,很明显右边的人物的皮肤看起来要更好一些:给人的视觉效果也更年轻一点. 磨皮前后 ...

  4. 有道翻译爬取【json】

    ''' @Modify Time @Author ------------ ------- 2019/9/2 0:19 laoalo ''' import requests import json i ...

  5. (转)运行pip报错:Fatal error in launcher: Unable to create process using '"'

    转:https://blog.csdn.net/cjeric/article/details/73518782 在新环境上安装python的时候又再次遇到了这个情况,这次留意了一下,发现原来的文章有错 ...

  6. 初学Cadence 一

    点击打开 Design Entry CIS 弹出 不要选 OrCAD Capture,这个组件和OrCAD Capture CIS 相比少了很多东西,对元件的管理不方便.选 OrCAD Capture ...

  7. 当主机ip变了修改gitlab的ip地址

    gitlab服务器IP地址更换后需要修改以下两个配置中的IP地址: /var/opt/gitlab/gitlab-rails/etc/gitlab.yml /etc/gitlab/gitlab.rb ...

  8. 测开之路七十三:用kafka实现消息队列之环境搭建

    一:装java环境,确保java能正确调用 kafka下载地址:http://kafka.apache.org/downloads 下载并解压kafka: 新建两个文件夹,用于存放zookeeper和 ...

  9. Game on a Tree Gym - 102392F(树上最大匹配)

    思路: 本质是求一个树上的最大匹配能否覆盖所有的点. dfs遍历,用qian[]数组记录当前节点的子树内有几个没有匹配的点(初始化为-1因为可以匹配掉一个子树中未匹配的点),pipei[]数组记录当前 ...

  10. [COCI2017.1]Deda —— 解锁线段树的新玩法

    众所周知,能用线段树做的题一定可以暴力 但考场上也只能想到暴力了,毕竟还是对线段树不熟练. deda 描述 有一辆车上有n个小孩,年龄为1~n,然后q个询问,M X A代表在第X站时年龄为A的小孩会下 ...