zoukankan      html  css  js  c++  java
  • ssm传递参数,前端中文乱码

    这个问题,百度一波有各种的“终极”、“最好”等等,我试了一下,比较不适合我这边的代码,流泪,最后还是用的是普适性比较好的方法,以后能力提升的在改。

    在传参前使用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}]
  • 相关阅读:
    Visual Studio 正则表达式替换
    NHibernate MappingException. No Persister
    C#枚举
    测试
    NHibernate & INotifyPropertyChanged
    NHibernate Profiler使用方法
    根据条件动态拼接LinQ的where条件字串
    wpf中ToolTip实现
    jquery的colorbox关闭并传递数据到父窗
    c#简易反射调用泛型方法
  • 原文地址:https://www.cnblogs.com/hahayixiao/p/15262828.html
Copyright © 2011-2022 走看看