form表单提交,后台实体类接收转义问题
生活随笔
收集整理的這篇文章主要介紹了
form表单提交,后台实体类接收转义问题
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
問題:前臺表單用ajax提交,data為validateForm.serializeArray(),后臺用實(shí)體類接收參數(shù),&符號被轉(zhuǎn)義為&但是從request中直接取值是沒問題的,請問如何解決實(shí)體類接收到的參數(shù)的轉(zhuǎn)義問題。
代碼如下:
前臺代碼:var formData = validateForm.serializeArray();$.ajax({type: 'POST',cache: false,url: basepath + "/newProjectAdjustment/saveProjectAdjustmentInfo.do",data: formData,dataType: "json",async:false,success: function (result) {if (result.success) {saveFlag = true;} else {parent.$.messager.alert("提示", result.msg != "操作成功" ? result.msg : projMessage.get("C008"), "info");}},error: function (result) {parent.$.messager.alert("提示", projMessage.get("C008"), "info");} }); return saveFlag; 后端代碼: @RequestMapping(value = "saveProjectAdjustmentInfo.do", method = RequestMethod.POST) @ResponseBody public AjaxJson saveProjectAdjustmentInfo(HttpServletRequest request, ProjectAdjustmentDTO projectAdjustmentInfo) throws InvocationTargetException, IllegalAccessException {Map params = FormFormatterUtil.formatFrom2Map(request);AjaxJson result = new AjaxJson();return result; }Debug: 這是實(shí)體類中接收的參數(shù):
這是request種接收的參數(shù):
建議1:
在實(shí)體參數(shù)前面加@RequestBody試試
建議2:
在實(shí)體類的set方法中使用StringEscapeUtils.unescapeHtml4()就能反轉(zhuǎn)義
總結(jié)
以上是生活随笔為你收集整理的form表单提交,后台实体类接收转义问题的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: [ERR] 1227 - Access
- 下一篇: flowable实战(十五)关于流程设计