指定响应的字符集为utf-8,将@RequestMapping注解的produces属性的值设置为{"text/plain;charset=utf-8", "text/html;charset=utf-8"}

1
2
3
4
5
6
7
8
9
@ResponseBody
@RequestMapping(value = "/test", produces = {"text/plain;charset=utf-8", "text/html;charset=utf-8"})
public String test() {
Student student = new Student();
student.setName("11");
student.setAge(10);
studentService.add(student);
return "添加成功";
}