问题描述:在controller用ModelAndView传值到jsp页面,jsp页面使用${user2}获取不到值。(项目是maven项目) 请问一下这是什么情况呀,在网上找了很久,还是没找到答案。这是controller部分@RequestMapping("/list") public ModelAndView queryUserList() {
List<User> userList = userService.queryUserList();
User user2 = userList.get(0); for (User user : userList) {
System.out.println("name="+user.getName());
}
ModelAndView model = new ModelAndView();// model.addAttribute("user2", user2.getName());
model.addObject("user2", user2.getName());
model.setViewName("my");
ModelMap modelMap = model.getModelMap();
String str = (String) modelMap.get("user2");
System.out.println("user2 = "+str); return model;
}这是jsp部分这是web.xml
添加回答
举报
0/150
提交
取消