第一种:
像这种是直接return的string,在@RequestMapping注解上加上produces属性就可以了,
produces={"text/html;charset=UTF-8;","application/json;"}
produces: 指定返回的内容类型,仅当request请求头中的(Accept)类型中包含该指定类型才返回;
将功能处理方法将生产json格式的数据,此时根据请求头中的Accept进行匹配,如请求头“Accept:application/json”时即可匹配;
组合使用是“或”的关系,将匹配“Accept:text/html”或“Accept:application/json”。
第二种:
设置response.setContentType("text/html;charset=UTF-8");和response.setCharacterEncoding("UTF-8");记住这个一定要在getWriter前进行设置。
不过一般使用了第一种后就不用再用第二种了。