用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 + "'";
ListcustomPage = custemInfoService.findAllByWhere(strWhere);
Mapdatasource=new LinkedHashMap();
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 + "'";
ListcustomPage = custemInfoService.findAllByWhere(strWhere);
Mapdatasource=new LinkedHashMap();
datasource.put("code",0);
datasource.put("count",2);
datasource.put("data",customPage);
return datasource;
}
本来@ResponseBody代表返回json格式,我又用Gson转了一次,所以有问题。