乱码问题
乱码一直是编程的常见问题,spring mvc 返回json数据时可能导致乱码,需要在controller中添加如下代码:
@RequestMapping("/test")
@ResponseBody
public ResponseEntity<User> test(HttpServletResponse response)
{
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.TEXT_PLAIN);
// headers.setContentType(MediaType.TEXT_PLAIN);
headers.set("content-type", "text/html; charset=UTF-8");
return new ResponseEntity<User>(new User(1, "我是测试的用力用例数据"), headers,
HttpStatus.OK);
}