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

  1. <dependency>
  2. <groupId>org.springframework</groupId>
  3. <artifactId>springloaded</artifactId>
  4. </dependency>
  5. <dependency>
  6. <groupId>org.springframework.boot</groupId>
  7. <artifactId>spring-boot-devtools</artifactId>
  8. </dependency>

访问静态资源

src/main/resources/static

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

自定义消息转化器

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

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

  1. <dependency>
  2. <groupId>com.alibaba</groupId>
  3. <artifactId>fastjson</artifactId>
  4. <version>1.2.15</version>
  5. </dependency>
  1. @SpringBootApplication(scanBasePackages = {"com.fly"})//默认是本包及子报
  2. public class SpringDemoApp extends WebMvcConfigurerAdapter {
  3. @Override
  4. public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
  5. //创建FastJson的消息转换器
  6. FastJsonHttpMessageConverter converter = new FastJsonHttpMessageConverter();
  7. //创建FastJson的配置对象
  8. FastJsonConfig config = new FastJsonConfig();
  9. //对Json数据进行格式化
  10. config.setSerializerFeatures(SerializerFeature.PrettyFormat);
  11. converter.setFastJsonConfig(config);
  12. converters.add(converter);
  13. }
  14. //不继承WebMvcConfigurerAdapter使用配置成Bean的方式
  15. //@Bean
  16. //public HttpMessageConverters fastJsonHttpMessageConverter(){
  17. // //创建FastJson的消息转换器
  18. // FastJsonHttpMessageConverter converter = new FastJsonHttpMessageConverter();
  19. // //创建FastJson的配置对象
  20. // FastJsonConfig config = new FastJsonConfig();
  21. // //对Json数据进行格式化
  22. // config.setSerializerFeatures(SerializerFeature.PrettyFormat);
  23. // converter.setFastJsonConfig(config);
  24. // return new HttpMessageConverters(converter);
  25. //}
  26. public static void main(String[] args){
  27. SpringApplication.run(SpringDemoApp.class,args);
  28. }
  29. }
  1. @RequestMapping("/person")
  2. public Object show(){
  3. Person person = new Person();
  4. person.setId(1);
  5. person.setDate(new Date());
  6. person.setName("fly傅立叶");
  7. return person;
  8. }

发现中文乱码了

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

**时间显示的是时间戳

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

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. Anaconda概念和使用方法

    Anaconda概述 Anaconda是一个用于科学计算的Python发行版,支持 Linux, Mac, Windows系统,提供了包管理与环境管理的功能,可以很方便地解决多版本python并存.切 ...

  2. 第一周训练 | STL和基本数据结构

    A - 圆桌问题: HDU - 4841 #include<iostream> #include<vector> #include<stdio.h> #includ ...

  3. [CSP-S模拟测试]:折纸(模拟)

    题目描述 小$s$很喜欢折纸.有一天,他得到了一条很长的纸带,他把它从左向右均匀划分为$N$个单位长度,并且在每份的边界处分别标上数字$0\sim n$.然后小$s$开始无聊的折纸,每次他都会选择一个 ...

  4. spring boot中注册拦截器

    拦截器是动态拦截Action调用的对象.它提供了一种机制可以使开发者可以定义在一个action执行的前后执行的代码,也可以在一个action执行前阻止其执行,同时也提供了一种可以提取action中可重 ...

  5. 牛客:t次询问,每次给你一个数n,求在[1,n]内约数个数最多的数的约数个数(数论+贪心)

    https://ac.nowcoder.com/acm/contest/907/B t次询问,每次给你一个数n,求在[1,n]内约数个数最多的数的约数个数 分析: 根据约数和定理:对于一个大于1正整数 ...

  6. 2017工业软件top100

  7. 洛谷P1546 最短网络 Agri-Net(最小生成树,Kruskal)

    洛谷P1546 最短网络 Agri-Net 最小生成树模板题. 直接使用 Kruskal 求解. 复杂度为 \(O(E\log E)\) . #include<stdio.h> #incl ...

  8. groub by 与 over partition by 的区别

    这个逻辑,写的很对.明白了这个意思. over partition by 前面一定要用汇总函数.groub by 就可以不用.本质都是汇总 SELECT a.* ,SUM(a.audit_status ...

  9. Harbor - 私有企业级 Docker 镜像仓库

    GitHub 地址 容器镜像服务 Docker镜像的基本使用 Docker:企业级私有镜像仓库Harbor使用 Harbor 是基于 Docker Registry 的企业级镜像仓库,安装后的使用方法 ...

  10. LeetCode 112. Path Sum 动态演示

    给一个目标值,判断一棵树从根到叶子是否至少有一条路径加起来的和等于目标值 比较典型的深度优先算法. 引入一个全局变量bResult, 一旦找到一条,就不再搜索其他的了. class Solution ...