1
ModelAttributeアノテーションを使用すると、リストボックスのように多くのものをフィードできます。リストボックスをフィードするより良い方法
各lisboxには、コントロールやフォームを使用し、リストボックスごとにオブジェクトのリストを持つ別の方法でフィードする方が良いですか?
ModelAttributeアノテーションを使用すると、リストボックスのように多くのものをフィードできます。リストボックスをフィードするより良い方法
各lisboxには、コントロールやフォームを使用し、リストボックスごとにオブジェクトのリストを持つ別の方法でフィードする方が良いですか?
コントローラクラスが、このリストボックスを持つものとそうでないものがある場合、コントローラクラスが異なる要求に使用されている場合(たとえば、コントローラが、リストおよびリストボックスを持つ作成および更新ページ)、@ModelAttribute
注釈付きメソッドを使用してモデルをポップすると、値が不要な場合でもこのメソッドが実行されることを意味します。 - 私は私の謙虚な考え方が悪いです。
あなたの質問を正しく理解していただければ幸いです。比較したい2つの選択肢のそれぞれの例を追加してください。
@RequestMapping("/users")
@Controller
TheWayIPreferController() {
@RequestMapping(params = "form", method = RequestMethod.GET)
public ModelAndView createForm() {
ModelMap uiModel = new ModelMap();
uiModel.addAttribute("userCreateCommand", new UserCreateCommand());
uiModel.addAttribute("securityRoles", this.securityRoleDao.readAll()));
uiModel.addAttribute("salutations", this.salutationDao.readAll()));
uiModel.addAttribute("locales", this.localeDao.readAll());
return new ModelAndView("users/create", uiModel);
}
@RequestMapping(method = RequestMethod.POST)
public ModelAndView create(final @Valid UserCreateCommand userCreateCommand, final BindingResult bindingResult) {
...
}
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
public ModelAndView show(@PathVariable("id") final User user) {
...
}
}
の代わり:
@RequestMapping("/users")
@Controller
TheWayIDiscourageController(){
@ModelAttribute("securityRoles")
public List<SecurityRoles> getSecurityRoles(){
return this.securityRoleDao.readAll();
}
@ModelAttribute("salutations")
public List<SecurityRoles> getSalutations(){
return this.salutationDao.readAll());
}
@ModelAttribute("locales")
public List<SecurityRoles> getLocals(){
return this.localeDao.readAll();
}
@RequestMapping(params = "form", method = RequestMethod.GET)
public ModelAndView createForm() {
return new ModelAndView("users/create", "userCreateCommand", new UserCreateCommand());
}
@RequestMapping(method = RequestMethod.POST)
public ModelAndView create(final @Valid UserCreateCommand userCreateCommand, final BindingResult bindingResult) {
...
}
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
public ModelAndView show(@PathVariable("id") final User user) {
...
}
}