首先,不要用get传中文,我试了一些方法发现不行,所以果断决定用post传参,
这里用 encodeURI 进行一次编码传入后端
注意:${tplname} 要加 '
$.ajax({ url: '/RM/controller/json/ConfigTemplateCustomController/fetchTemplateCustomContentsByTplName/tplname/post', type: 'POST', async: false, data:{ 'tplname':encodeURI('${tplname}') }, success:
这样解码后再 getBytes 就解决了
@RequestMapping(value = "controller/json/ConfigTemplateCustomController/fetchTemplateCustomContentsByTplName/tplname/post", method = RequestMethod.POST) @ResponseBody public BaseResult fetchTemplateCustomContentsByTplName(String tplname) throws UnsupportedEncodingException { tplname = URLDecoder.decode(tplname,"utf-8"); tplname = new String(tplname.getBytes("ISO-8859-1"),"UTF-8"); return ResultUtil.success().add("TemplateCustom", configTemplateCustomService.selectByPrimaryKey(tplname)); }