这个问题,百度一波有各种的“终极”、“最好”等等,我试了一下,比较不适合我这边的代码,流泪,最后还是用的是普适性比较好的方法,以后能力提升的在改。
在传参前使用response.setContentType("text/html;charset=UTF-8");即可,
@RequestMapping("/allPagePaper")
public void listPaper(HttpServletResponse response) {
response.setContentType("text/html;charset=UTF-8");
List<Paper> list = paperService.queryPagePaper(0,10);
String pageList= JSON.toJSONString(list);
try {
//response.getWriter().print:传递参数
//pageNumber:需要传递的参数
response.getWriter().print(pageList);
}catch (Exception e){
e.printStackTrace();
}
}
效果:
修改之前
[{"paperDetail":"??","paperId":1,"paperName":"??","paperNum":100},{"paperDetail":"??","paperId":4,"paperName":"???","paperNum":3},{"paperDetail":"2","paperId":6,"paperName":"22","paperNum":102422},{"paperDetail":"2","paperId":7,"paperName":"2","paperNum":2},{"paperDetail":"1","paperId":8,"paperName":"1","paperNum":1},{"paperDetail":"23","paperId":9,"paperName":"2","paperNum":2},{"paperDetail":"3","paperId":10,"paperName":"3","paperNum":3},{"paperDetail":"4","paperId":11,"paperName":"4","paperNum":4},{"paperDetail":"5","paperId":12,"paperName":"5","paperNum":5},
[{"paperDetail":"娴嬭瘯","paperId":1,"paperName":"娴嬭瘯","paperNum":100},{"paperDetail":"璇︽儏","paperId":4,"paperName":"鏁版嵁闆�","paperNum":3},{"paperDetail":"2","paperId":6,"paperName":"22","paperNum":102422},{"paperDetail":"2","paperId":7,"paperName":"2","paperNum":2},{"paperDetail":"1","paperId":8,"paperName":"1","paperNum":1},{"paperDetail":"23","paperId":9,"paperName":"2","paperNum":2},{"paperDetail":"3","paperId":10,"paperName":"3","paperNum":3},{"paperDetail":"4","paperId":11,"paperName":"4","paperNum":4},{"paperDetail":"5","paperId":12,"paperName":"5","paperNum":5},{"paperDetail":"7","paperId":14,"paperName":"7","paperNum":7}]
修改后
[{"paperDetail":"测试","paperId":1,"paperName":"测试","paperNum":100},{"paperDetail":"详情","paperId":4,"paperName":"数据集","paperNum":3},{"paperDetail":"2","paperId":6,"paperName":"22","paperNum":102422},{"paperDetail":"2","paperId":7,"paperName":"2","paperNum":2},{"paperDetail":"1","paperId":8,"paperName":"1","paperNum":1},{"paperDetail":"23","paperId":9,"paperName":"2","paperNum":2},{"paperDetail":"3","paperId":10,"paperName":"3","paperNum":3},{"paperDetail":"4","paperId":11,"paperName":"4","paperNum":4},{"paperDetail":"5","paperId":12,"paperName":"5","paperNum":5},{"paperDetail":"7","paperId":14,"paperName":"7","paperNum":7}]