dyc87112 / SpringBoot-Learning

《Spring Boot基础教程》,2.x版本持续连载中!点击下方链接直达教程目录!
https://blog.didispace.com/spring-boot-learning-2x/
15.7k stars 4.88k forks source link

chapter 2-1 #51

Open Godxia opened 4 years ago

Godxia commented 4 years ago

idea测试出中文乱码问题。 java.lang.AssertionError: Response content Expected: "[{\"id\":1,\"name\":\"测试大师\",\"age\":20}]" but: was "[{\"id\":1,\"name\":\"???è???¤§???\",\"age\":20}]" 搜了半天,file encoding都改成utf-8了,但是还是乱码。

ponyhu commented 4 years ago

@RequestMapping(value = "/users", produces = "application/json;charset=utf8")

类上的注解,改为这样就可以了。

通过实现 WebMvcConfigurer 中的configureMessageConverters 这种方式,经我实测无效。