Spring Controller (provincia)의 콘텐츠로 목록을 채웠고 (provincia)에서 선택한 값을 가져 오는 데 필요한 다른 개체 (profile2)가 있습니다.
@RequestMapping(value = "/editprofileabout4", method = RequestMethod.GET)
public ModelAndView editProfileAbout4(ModelAndView modelAndView) {
Usuario usuario = getUsuario();
Profile profile = profileService.getUserProfile(usuario);
Profile2 profile2 = profile2Service.getUserProfile2(usuario);
List<Provincia> provincia = provinciaService.readAllProvincia();
Profile webProfile = new Profile();
webProfile.safeCopyFrom(profile);
modelAndView.getModel().put("edituserprofile2th", usuario);
modelAndView.getModel().put("editprofile2about2th", profile2);
modelAndView.getModel().put("editprovincia2th", provincia);
modelAndView.setViewName("editprofileabout4");
return modelAndView;
}
@RequestMapping(value = "/doeditprofileabout4", method = RequestMethod.POST)
public ModelAndView editProfileAbout4(ModelAndView modelAndView, @Valid Profile2 profile2, @Valid Provincia provincia, BindingResult result) {
modelAndView.setViewName("editprofileabout4");
System.out.println(" !!!!!!!!!!!!! PROFILE2a: " + profile2.getBirthdate());
System.out.println(" !!!!!!!!!!!!! PROFILE2b: " + profile2.getGender());
System.out.println(" !!!!!!!!!!!!! PROFILE2d: " + profile2.getProvincia());
System.out.println(" !!!!!!!!!!!!! PROFILE2x: " + provincia.toString());
Usuario usuario = getUsuario();
Profile2 profile = profile2Service.getUserProfile2(usuario);
profile.setCountry(profile2.getCountry());
profile.setGender(profile2.getGender());
profile.setBirthdate(profile2.getBirthdate());
profile.setProvincia(provincia);
if (!result.hasErrors()) {
profile2Service.save(profile);
modelAndView.setViewName("redirect:/editprofileabout4");
}
return modelAndView;
}
내 HTML에는 다음이 있습니다.
<form class="sky-form" id="sky-form4" action="#" th:object="${editprofile2about2th}" th:action="@{/doeditprofileabout4}" method="post">
<section>
<div class="col-lg-3">
<select class="form-control" th:object="${editprovincia2th}" id="ddl" name="ddl">
<option value="" th:text="#{editprofile.about4.provincia}">Seleccionar Provincia</option>
<option th:each="dropDownItem : ${editprovincia2th}"
th:value="${dropDownItem.id_provincia}"
th:text="${dropDownItem.provincia}"></option>
</select>
</div>
</section>
하지만 목록의 값에 해당하는 선택한 키와 값 (th : select)을 추출하여 컨트롤러로 다시 가져 오는 방법에 대한 작업 예제를 찾을 수 없습니다 (또는 provincia 유선 개체가있는 프로필 2 개체로 이동 ). Post 후 컨트롤러에서 provincia에 대한 null 값을 얻습니다.
HTML에 (select th : field = "* {provincia}")를 포함하면 오류가 발생합니다. 예기치 않은 오류가 발생했습니다 (type = Internal Server Error, status = 500). 프로세서 'org.thymeleaf.spring4.processor.attr.SpringSelectFieldAttrProcessor'실행 중 오류 (editprofileabout4 : 120) Bean 클래스 [java.util.ArrayList]의 유효하지 않은 속성 'provincia': Bean 속성 'provincia'를 읽을 수 없거나 잘못된 getter 메서드 : getter의 반환 유형이 setter의 매개 변수 유형과 일치합니까?
도움을 주셔서 감사합니다. 모든 문서에 감사드립니다.
Thymeleaf 문서에 다음과 같이 명시되어 있기 때문에 요소 th:object
에서 속성 을 제거 select
하고 양식에 대해 하나만 유지해야합니다.
태그 안에 있으면 다른 th : object 속성을 지정할 수 없습니다. 이는 HTML 양식을 중첩 할 수 없다는 사실과 일치합니다.
th:object
양식의 속성은 양식 지원 Bean, 즉 양식을 통해 전송하는 모든 값을 보유 할 수있는 객체 (예 : provincia)를 참조해야합니다.
현재 존재하지 않는 List 객체의 provincia 속성에 액세스하려고 합니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다