Question: The front-end form is submitted with ajax, the data is validateForm.serializeArray(), and the back-end uses entity classes to receive parameters. The & symbol is escaped as &, but it is no problem to directly get the value from the request. How to solve the problem of entity classes? Escape problem of received parameters.
code show as below:
前台代码: 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: 这是实体类中接收的参数:
这是request种接收的参数:
Try adding @RequestBody in front of the entity parameters
Use StringEscapeUtils.unescapeHtml4() in the set method of the entity class to reverse escape.