Spring MVCを使用しorg.springframework.ui.Model
て、コントローラー内のメソッドパラメーターで指定する必要がないように、を因数分解する方法はありますか?
言い換えれば、私は現在このようにそれをやっています:
public abstract class AbstractController {
@Autowired
protected MultipartHttpServletRequest request;
}
@Controller
public class SigninController extends AbstractController {
@RequestMapping(value = "/signin", method = RequestMethod.GET)
public String signin(@ModelAttribute User user, Model model) {
// do stuff with user (parameter)
// do stuff with model (parameter) <--
// do stuff with request (attribute)
return "/signin/index";
}
}
そして、私はそのようにしたいと思います:
public abstract class AbstractController {
@Autowired
protected MultipartHttpServletRequest request;
@Autowired
protected Model model;
}
@Controller
public class SigninController extends AbstractController {
@RequestMapping(value = "/signin", method = RequestMethod.GET)
public String signin(@ModelAttribute User user) {
// do stuff with user (parameter)
// do stuff with model (attribute) <--
// do stuff with request (attribute)
return "/signin/index";
}
}
ただし、URLを呼び出すと、例外がスローされます。
...Could not autowire field: protected org.springframework.ui.Model...
...No matching bean of type [org.springframework.ui.Model] found for dependency...
を使用したときに同じエラーが発生しましたorg.springframework.ui.ModelMap
。
天才的な解決策はありますか?
助けてくれてありがとう:)