데이터를 조회 객체에 게시하는 양식이 있습니다. Inquiry 개체는 명시 적으로 정의 된 생성자가없는 Controller의 ModelAttribute입니다. age
입력 요소의 value 속성을 양식의 빈 문자열로 설정 했음에도 불구하고 0으로 처리됩니다. 이것은 우리가 0으로 초기화되는 Inquiry 객체로부터 age
의 기존 값을 얻는다고 생각하게 만듭니다. 이미 enquiry.age
에 게시하는 방법이 있습니까? 내 페이지에 현재 값이 표시되지 않습니까? 내 컨트롤러의양식 입력시 값을 무시하는 스프링 MVC 바인딩
내 양식
<form:form commandName="enquiry" method="post" action="mycontext/jsp/enquiry-search">
<form:input path="name" value=""/>
<form:input path="age" value=""/>
</form:form>
부
@RequestMapping(value = "/enquiry/{screenType}", method = {RequestMethod.GET, RequestMethod.POST})
@ResponseStatus(HttpStatus.OK)
public String getEnquiryScreen(@ModelAttribute ("enquiry") Enquiry enquiry, @PathVariable("screenType") String screenType) {
return "enquiry";
}
@ModelAttribute("enquiry")
public Enquiry getEnquiry() {
return new Enquiry();
}
내 문의 클래스
public class Enquiry {
private String name;
private int age;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}