帖子后列表框为空
使用spring 3.0,
当我点击提交信息(post)时,这里调用这个方法
@RequestMapping(method = RequestMethod.POST)
public String userResult(@ModelAttribute UserForm userForm, Model model) {
List<UserInfo> listUserInfo = userService.searchUserInfo(userForm.getsearchCriteria());
userForm.setListUserInfo(listUserInfo);
userForm.setSearchDone(true);
model.addAttribute(userForm);
return "userSearch";
}
,jsp有很多列表框,当我检查userForm和模型时, 所有列表框均为空... 有办法避免吗?因为我每次都需要对数据库进行一些调用,
谢谢
with spring 3.0
when i click to submit information (post) this method is called here
@RequestMapping(method = RequestMethod.POST)
public String userResult(@ModelAttribute UserForm userForm, Model model) {
List<UserInfo> listUserInfo = userService.searchUserInfo(userForm.getsearchCriteria());
userForm.setListUserInfo(listUserInfo);
userForm.setSearchDone(true);
model.addAttribute(userForm);
return "userSearch";
}
the jsp have many listbox, when i check the userForm and model,
all listbox is null...
is there a way to avoid that? because i will need to do some call to db every time
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以通过这种方式在控制器方法中使用@ModelAttribute。
当您使用 @ModelAttribute("list1") 注解该方法时,该方法将在控制器中的任何方法之前自动执行,然后结果将添加到模型中的“list1”处。您可以将 list1 设置为您需要的 value 属性,并根据需要添加任意数量的带 @ModelAttribute 注解的控制器。
You can use @ModelAttribute in a controller method in this way.
When you annotate the method with @ModelAttribute("list1") then this method will automatically be executed before any method in the controller and then the result will be added in the model at "list1". You can set list1 to the value property you need and add as many @ModelAttribute annotated controllers as you need.