error log
Neither BindingResult nor plain target object for bean name 'domainReportCreateForm' available as request attribute
html
<form id="createForm" th:attr="action=@{/domainReport/create}" th:object="${domainReportCreateForm}" method="post" enctype="multipart/form-data">
controller
public String create(@Validated @ModelAttribute DomainReportForm domainReportCreateForm, BindingResult result,
Model model) {
解決
public String create(@Validated @ModelAttribute("domainReportCreateForm") DomainReportForm domainReportCreateForm, BindingResult result,
Model model) {
- クラス名とインスタンス名が違うときは明示的にしなければいけない
- パラメータ順序も大切
参考
I think the trouble because you placed BindingResult incorrect. Replace it with MultipartHttpServletRequest, it must be after the validating parameter:
@RequestMapping(method= RequestMethod.POST, value = "/create")
public String createTest(@Valid @ModelAttribute("testForm") TestForm testForm, BindingResult bindingResult, MultipartHttpServletRequest request) throws IOException {
if (bindingResult.hasErrors())
return "createtestform";