0
이에 게시하기 전에 폼 입력을 확인하는 내가지고있어 오류입니다 :Thymeleaf 오류 API 광고
:java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'e' available as request attribute at org.springframework.web.servlet.support.BindStatus.<init>(BindStatus.java:144) ~[spring-webmvc-4.3.7.RELEASE.jar:4.3.7.RELEASE] .... ....
GET
방법 (표시 형태)
내 원래 POST
메소드가 작동하지 않아서 postToEntity
API 호출과 관련된 다른 코드를 제외하기 위해 더 얇은 POST
메소드를 만들려고했습니다.
@PostMapping("/temp")
public String temp(@Valid @ModelAttribute EntryForm e, BindingResult bindingResult){
// returns 1 in debug mode (error for the only field (name) in the form, so OK
// int ct = bindingResult.getErrorCount();
if(bindingResult.hasErrors()){
// this Thymeleaf view/template is reached
return "forms/frmEntry";
}
// dummy Thymeleaf view (doesn't exist)
return "proslodokraja";
}
내 양식 :
<form action="/consumer/temp" th:object="${e}" method="post" class="col-md-6">
// in my code, this hidden field is commented out (for now)
<input type="hidden" th:field="*{id}" />
<p>
Name: <input type="text" th:field="*{name}" class="form-control" />
<br/>
<span th:if="${#fields.hasErrors('name')}" th:errors="*{name}">Name error</span>
</p>
<p>
<input type="submit" value="Submit" class="btn btn-primary" />
<input type="reset" value="Reset" class="btn btn-default" />
</p>
</form>
양식 Bean
:
public class EntryForm {
private Long id;
@NotNull
@Length(min=2) // hibernate import!
private String name;
public EntryForm(){ }
public EntryForm(String name) { this.name = name; }
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
하지 꽤 있습니다. 내가 질문을 게시하기 직전에'entry'를'e'로 바꿨습니다. 왜냐하면 Spring의 코드 스 니펫에 따라 조정하려고했기 때문입니다. 하지만 템플릿과 포스트 메소드에서 모두'entry'로 되돌아 왔고 예상대로 오류가 남아있었습니다. – developer10
나는 당신이 결국 옳았다 고 생각합니다. 나는'GET' 메소드에서'entry'로 다시 돌아가는 것을 잊어 버렸습니다. 마지막으로, 폼 bean을'entryForm'으로 참조하기로 결정했고 마침내 작동하기 시작했습니다. 나는 너의 대답을 받아 들일거야. 도와 줘서 고마워! – developer10