私はコントローラにデータhtmlを渡そうとしますが、私はそのようなエラーがあります。私のGETメソッドは明らかに動作しますが、POSTメソッドがspring boot- thymeleaf pass html to controller
java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'post' available as request attribute
at org.springframework.web.servlet.support.BindStatus.<init>(BindStatus.java:144) ~[spring-webmvc-4.3.4.RELEASE.jar:4.3.4.RELEASE]
at org.thymeleaf.spring4.util.FieldUtils.getBindStatusFromParsedExpression(FieldUtils.java:401) ~[thymeleaf-spring4-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at org.thymeleaf.spring4.util.FieldUtils.getBindStatus(FieldUtils.java:328) ~[thymeleaf-spring4-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at org.thymeleaf.spring4.util.FieldUtils.getBindStatus(FieldUtils.java:294) ~[thymeleaf-spring4-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at org.thymeleaf.spring4.processor.attr.AbstractSpringFieldAttrProcessor.processAttribute(AbstractSpringFieldAttrProcessor.java:98) ~[thymeleaf-spring4-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at org.thymeleaf.processor.attr.AbstractAttrProcessor.doProcess(AbstractAttrProcessor.java:87) ~[thymeleaf-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at org.thymeleaf.processor.AbstractProcessor.process(AbstractProcessor.java:212) ~[thymeleaf-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at org.thymeleaf.dom.Node.applyNextProcessor(Node.java:1017) ~[thymeleaf-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at org.thymeleaf.dom.Node.processNode(Node.java:972) ~[thymeleaf-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at org.thymeleaf.dom.NestableNode.computeNextChild(NestableNode.java:695) ~[thymeleaf-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at org.thymeleaf.dom.NestableNode.doAdditionalProcess(NestableNode.java:668) ~[thymeleaf-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at org.thymeleaf.dom.Node.processNode(Node.java:990) ~[thymeleaf-2.1.5.RELEASE.jar:2.1.5.RELEASE]
を動作しないで、これは最終的に私のコントローラメソッドは、ここで私はできません
@RequestMapping(value = "/{id}", method = RequestMethod.POST)
public ModelAndView savePost(@Valid Post post,@PathVariable("id")Long id){
ModelAndView modelAndView =new ModelAndView();
Title title = titleService.getTitleById(id);
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
User user = userService.findUserByEmail(auth.getName());
Date date = new Date();
Post post1 = new Post();
post1.setPostBody(post.getPostBody());
post1.setPostDate(date);
post1.setPostSender(user);
post1.setPostTitle(title);
postService.savePost(post1);
modelAndView.addObject("post",post1);
modelAndView.setViewName("homePage2");
return modelAndView;
}
である私のHTMLフォーム
<form autocomplete="off" action="#" th:action="@{/(${titleId})}"
th:object="${post}" method="post" class="form-horizontal"
role="form">
<h2>Formu doldur aramıza katıl..</h2>
<div class="form-group">
<div class="col-sm-9">
<input type="text" th:field="*{postBody}" placeholder="yorumla"
class="form-control" />
</div>
</div>
<div class="form-group">
<div class="col-sm-9">
<button type="submit" class="btn btn-primary btn-block">Kayıt Ol</button>
</div>
</div>
</form>
ですなぜ私はエラーがあるか理解する。
ありがとうございます。ありがとうございます – yyusufaslan
その後、正しい答えとして受け入れます – StanislavL