【视频&交流平台】
http://study.163.com/course/introduction.htm?courseId=1004329008&utm_campaign=commission&utm_source=400000000155061&utm_medium=share
http://study.163.com/course/introduction.htm?courseId=1004638001&utm_campaign=commission&utm_source=400000000155061&utm_medium=share
https://gitee.com/happyangellxq520/spring-boot
http://412887952-qq-com.iteye.com/blog/2321532
需求缘起:
在录制视频《Spring Boot集成jersey》的时候,在返回中文的时候,出现了乱码,这个当时在集成的时候,返回的是英文,所以并没有发现这个问题,这里对这个问题给出解决方案。
请求源代码:
我们这里先提供请求方法的源代码:
@GET//get请求. @Path("/getUser") @Produces(MediaType.APPLICATION_JSON) public Map<String,Object> getUser(){ Map<String,Object> map = new HashMap<String,Object>(); map.put("id","1000"); map.put("name","张三"); map.put("age","25"); System.out.println(map.get("name")); return map; }
方案一
通过以上代码,我们能清楚在map对象中的name的话,是不会出现乱码的,那么就在返回的时候,response,并没有设置编码,那么怎么在返回的时候,指定编码呢,只需要稍微修改上面的代码即可:
@GET//get请求. @Path("/getUser") @Produces(MediaType.APPLICATION_JSON+";charset=UTF-8")
在这里我们手动配置了utf-8编码。
方案二
我们先说说方案一存在的问题:
(1)编码不方便,每个开发人员都需要进行编码;
(2)编码调整或者是后期发现中文,要调整的地方比较多;
(3)代码侵入性太强;
那么我们有更好的方案嘛,当然有,只需要在application.properties配置两个信息:
spring.http.encoding.force=true spring.http.encoding.charset=UTF-8
到这里就可以完美解决中文乱码问题。
相关推荐
Spring Boot 学习笔记,包括底层实现原理及代码实战,非常齐全,助你快速打通 Spring Boot 的各个环节。 1. Spring boot helloworld 2. Spring boot 返回 json 数据 3. Spring boot 使用其他 json 转换框架 4. ...
Pro Spring Boot is your authoritative hands-on practical guide for increasing your Spring Framework-based enterprise Java and cloud application productivity while decreasing development time using the...
2018.02.Spring Boot 2.0 Cookbook 2nd
Spring Boot 学习示例 Spring Boot 2.0 Mysql 5.6 JDK 1.8 Maven license Spring Boot 使用的各种示例,以最简单、最实用为标准,此开源项目中的每个示例都以最小依赖,最简单为标准,帮助初学者快速掌握 Spring ...
Apress.Beginning.Spring.Boot.2.pdfApress.Beginning.Spring.Boot.2.pdfApress.Beginning.Spring.Boot.2.pdfApress.Beginning.Spring.Boot.2.pdfApress.Beginning.Spring.Boot.2.pdf
org.springframework.aop-3.0.4.RELEASE.jar org.springframework.asm-3.0.4.RELEASE.jar org.springframework.aspects-3.0.4.RELEASE.jar org.springframework.beans-3.0.4.RELEASE.jar org.springframework....
This book will help you understand what Spring Boot is, how Spring Boot helps you build Spring-based applications quickly and easily, and the inner workings of Spring Boot using easy-to-follow ...
赠送jar包:spring-boot-autoconfigure-2.3.12...标签:springframework、boot、spring、autoconfigure、中文文档、jar包、java; 使用方法:解压翻译后的API文档,用浏览器打开“index.html”文件,即可纵览文档内容。
Packt.Spring.Boot.2.0.Cookbook.2nd.Edition. Packt.Spring.Boot.2.0.Cookbook.2nd.Edition.
Spring-Boot-Reference-Guide, Spring Boot Reference Guide中文翻译 -《Spring Boot参考指南》
Learning.Spring.Boot.2.0.2ddddnd.EditionLearning.Spring.Boot.2.0.2ddddnd.EditionLearning.Spring.Boot.2.0.2ddddnd.Edition
包含翻译后的API文档:spring-boot-configuration-processor-2.3.12.RELEASE-javadoc-API文档-中文(简体)版.zip; Maven坐标:org.springframework.boot:spring-boot-configuration-processor:2.3.12.RELEASE; 标签...
标签:springframework、boot、spring、中文文档、jar包、java; 使用方法:解压翻译后的API文档,用浏览器打开“index.html”文件,即可纵览文档内容。 人性化翻译,文档中的代码和结构保持不变,注释和说明精准...
Pro Spring Boot is your authoritative hands-on practical guide for increasing your Spring Framework-based enterprise Java and cloud application productivity while decreasing development time using the...
Spring Boot 项目旨在简化创建产品级的 Spring 应用和服务。你可通过它来选择不同的 Spring 平台。可创建独立的 Java 应用和 Web 应用,同时提供了命令行工具来允许 'spring scripts'.下图显示 Spring Boot 在 ...
This book has description how to handle message and what is best practice.
NULL 博文链接:https://412887952-qq-com.iteye.com/blog/2294952
1、Spring Cloud是基于Spring Boot来实现的。 2、Spring Cloud是一系列工具框架的集合体。 3、Spring Cloud提供了一套完整的微服务解决方案。 16套Java架构师,集群,高可用,高可扩展,高性能,高并发,性能优化,...
Spring Boot单元测试
包含翻译后的API文档:spring-boot-autoconfigure-2.0.6.RELEASE-javadoc-API文档-中文(简体)-英语-对照版.zip; Maven坐标:org.springframework.boot:spring-boot-autoconfigure:2.0.6.RELEASE; 标签:spring、...