springboot+themleaf+JavaScript进行json传值

springboot+themleaf+JavaScript进行json传值跟springmvc+jsp+jstl的传值有点区别。
1、在maven项目的pom.xml引入net.sf.json加包,如下:

   
		net.sf.json-lib
		json-lib
		2.4
		jdk15
	

2、在controller控制内中的代码如下:

@RequestMapping(value = "/user_UserList", method = RequestMethod.GET)
public String UserList(ModelMap model,HttpServletResponse response){
	List lst=userMapper.allUser();
	JSONArray ja=JSONArray.fromObject(lst);
	model.addAttribute("userList", ja);
	return "/SystemManager/BaseInformation/UserList";
}

注:上面接口中,是将一个list集合转换成json,再传到前段;
3、在themleaf的JavaScript中接收json值

  var result='[[${userList}]]';

但实际接收到的值如下:

 result='[{"address":"22","id":"1","phone":"2","sex":"2","username":"2"},
 {"address":"2","id":"2","phone":"2","sex":"2","username":"2"}]'

注:对于上述问题,可以采取如下转换(完整js如下):

   

你可能感兴趣的:(web前段,springboot,themleaf,json,JavaScript)