layui table中文乱码

用layui table接收到的后台数据是中文乱码。

用的是springmvc,设置和请求和响应还有tomcat都是utf-8还是乱码。

最后找到原因:

改之前

    @RequestMapping(value = "/querycustom",method = RequestMethod.POST,produces ={"text/html;charset=UTF-8;", "application/json;"})
    @ResponseBody
    public Object queryCustomByWhere(
            @RequestParam("CUS004") String CUS004,
            @RequestParam("industry") String industry,
            @RequestParam("salesman") String salesman,
            @RequestParam("CUS013") String CUS013,
            @RequestParam("CUS009start") String CUS009start,
            @RequestParam("CUS009end") String CUS009end,
            @RequestParam("CUS011start") String CUS011start,
            @RequestParam("CUS011end") String CUS011end
    ) {
        String strWhere = "1=1";
        if (!StringUtils.isEmpty(CUS004))
            strWhere += " AND CUS004='" + CUS004 + "'";
        if (!StringUtils.isEmpty(industry))
            strWhere += " AND CUS010='" + industry + "'";
        if (!StringUtils.isEmpty(salesman))
            strWhere += " AND CUS012='" + salesman + "'";
        if (!StringUtils.isEmpty(CUS013))
            strWhere += " AND CUS013='" + CUS013 + "'";
        if (!StringUtils.isEmpty(CUS009start))
            strWhere += " AND CUS009>='" + CUS009start + "'";
        if (!StringUtils.isEmpty(CUS009end))
            strWhere += " AND CUS009<='" + CUS009end + "'";
        if (!StringUtils.isEmpty(CUS011start))
            strWhere += " AND CUS011>='" + CUS011start + "'";
        if (!StringUtils.isEmpty(CUS011end))
            strWhere += " AND CUS011<='" + CUS011end + "'";
        List<Custom> customPage = custemInfoService.findAllByWhere(strWhere);
        Map<String,Object> datasource=new LinkedHashMap<String,Object>();
        datasource.put("code",0);
        datasource.put("count",2);
        datasource.put("data",customPage);
        Gson gson=new Gson();
        String result=gson.toJson(datasource);
        return result;
    }

改之后

@RequestMapping(value = "/querycustom",method = RequestMethod.POST,produces ={"text/html;charset=UTF-8;", "application/json;"})
    @ResponseBody
    public Object queryCustomByWhere(
            @RequestParam("CUS004") String CUS004,
            @RequestParam("industry") String industry,
            @RequestParam("salesman") String salesman,
            @RequestParam("CUS013") String CUS013,
            @RequestParam("CUS009start") String CUS009start,
            @RequestParam("CUS009end") String CUS009end,
            @RequestParam("CUS011start") String CUS011start,
            @RequestParam("CUS011end") String CUS011end
    ) {
        String strWhere = "1=1";
        if (!StringUtils.isEmpty(CUS004))
            strWhere += " AND CUS004='" + CUS004 + "'";
        if (!StringUtils.isEmpty(industry))
            strWhere += " AND CUS010='" + industry + "'";
        if (!StringUtils.isEmpty(salesman))
            strWhere += " AND CUS012='" + salesman + "'";
        if (!StringUtils.isEmpty(CUS013))
            strWhere += " AND CUS013='" + CUS013 + "'";
        if (!StringUtils.isEmpty(CUS009start))
            strWhere += " AND CUS009>='" + CUS009start + "'";
        if (!StringUtils.isEmpty(CUS009end))
            strWhere += " AND CUS009<='" + CUS009end + "'";
        if (!StringUtils.isEmpty(CUS011start))
            strWhere += " AND CUS011>='" + CUS011start + "'";
        if (!StringUtils.isEmpty(CUS011end))
            strWhere += " AND CUS011<='" + CUS011end + "'";
        List<Custom> customPage = custemInfoService.findAllByWhere(strWhere);
        Map<String,Object> datasource=new LinkedHashMap<String,Object>();
        datasource.put("code",0);
        datasource.put("count",2);
        datasource.put("data",customPage);
        return datasource;
    }

本来@ResponseBody代表返回json格式,我又用Gson转了一次,所以有问题。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值