jsp界面中将后端的java复杂对象传递给前端js对象的方法:
用JSP表达式--加JSON数据转换
复杂对象需要转成JSON数据进行前后端传输,所以后端传值前、前端接收对象后都需要进行JSON数据处理。
后端代码:
@RequestMapping(value = "/user/common/defaultReport")
public String defaultReport(HttpServletRequest req, Model model) {
List audfList = processCusReportService.getUDFList();
req.setAttribute("audfList", audfList);
return "user/activitiCommon/defaultReportView";
}
前端代码jsp代码:
pageEncoding="UTF-8" %>
List audfList = (List) request.getAttribute("audfList");
String audfListStr = JSONArray.fromObject(audfList).toString();
%>
maaaaaaaaaagic~var reportList = JSON.parse('');
console.log(reportList)