layui 汉字乱码_layui table中文乱码

时间:2025-01-29 08:23:51

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

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

最后找到原因:

改之前

@RequestMapping(value = "/querycustom",method = ,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 (!(CUS004))

strWhere += " AND CUS004='" + CUS004 + "'";

if (!(industry))

strWhere += " AND CUS010='" + industry + "'";

if (!(salesman))

strWhere += " AND CUS012='" + salesman + "'";

if (!(CUS013))

strWhere += " AND CUS013='" + CUS013 + "'";

if (!(CUS009start))

strWhere += " AND CUS009>='" + CUS009start + "'";

if (!(CUS009end))

strWhere += " AND CUS009<='" + CUS009end + "'";

if (!(CUS011start))

strWhere += " AND CUS011>='" + CUS011start + "'";

if (!(CUS011end))

strWhere += " AND CUS011<='" + CUS011end + "'";

ListcustomPage = (strWhere);

Mapdatasource=new LinkedHashMap();

("code",0);

("count",2);

("data",customPage);

Gson gson=new Gson();

String result=(datasource);

return result;

}

改之后

@RequestMapping(value = "/querycustom",method = ,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 (!(CUS004))

strWhere += " AND CUS004='" + CUS004 + "'";

if (!(industry))

strWhere += " AND CUS010='" + industry + "'";

if (!(salesman))

strWhere += " AND CUS012='" + salesman + "'";

if (!(CUS013))

strWhere += " AND CUS013='" + CUS013 + "'";

if (!(CUS009start))

strWhere += " AND CUS009>='" + CUS009start + "'";

if (!(CUS009end))

strWhere += " AND CUS009<='" + CUS009end + "'";

if (!(CUS011start))

strWhere += " AND CUS011>='" + CUS011start + "'";

if (!(CUS011end))

strWhere += " AND CUS011<='" + CUS011end + "'";

ListcustomPage = (strWhere);

Mapdatasource=new LinkedHashMap();

("code",0);

("count",2);

("data",customPage);

return datasource;

}

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