일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- 티스토리 블로그
- 스프링
- MSI
- 인터페이스
- 환경설정
- 전화번호부
- 이클립스
- while
- 깃허브 블로그
- ORA-01407
- 오류
- 설정
- ORA-02292
- 오류모음
- 무결성 제약조건
- Oracle
- 파워서플라이
- 백준문제풀이
- Ajax
- for문
- 자바
- 별 찍기
- 백준문제
- 순환문
- 이클립스단축기
- jsp
- 오라클
- spring
- 공부
- 백준
Archives
- Today
- Total
danDevlog
form태그 value="" 오류 (@ModelAttribute) BeanPropertyBindingResult 본문
728x90
WARN : org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver - Resolved [org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBindingResult: 2 errors
Field error in object 'criteria' on field 'amount': rejected value []; codes [typeMismatch.criteria.amount,typeMismatch.amount,typeMismatch.int,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [criteria.amount,amount]; arguments []; default message [amount]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'int' for property 'amount'; nested exception is java.lang.NumberFormatException: For input string: ""]
Field error in object 'criteria' on field 'pageNum': rejected value []; codes [typeMismatch.criteria.pageNum,typeMismatch.pageNum,typeMismatch.int,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [criteria.pageNum,pageNum]; arguments []; default message [pageNum]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'int' for property 'pageNum'; nested exception is java.lang.NumberFormatException: For input string: ""]]
해당오류는 get방식의 form태그에서 값을 가져오는 과정에서 value의 값이 "" 로 들어가서 생긴 오류이다.
오류 트레이스를 읽어보면 int타입값이 와야하는데 String 값이 들어왔다해서 해당 VO로 가서 다시보고,
Mapper도 다시 보고 하면서 2시간정도 낭비했던것같다. 하지만 맨 마지막 부분에 For input string : "" 라는것을 보고
브라우저 페이지의 개발자 모드에 들어가서 form 태그 부분의 value값을 보니 다른건 값이 들어와있지만 criteria객체의 변수들만 없다는것을 알 수 있었다.
https://animal-park.tistory.com/86 이분의 글을 참고하였다.
// 변경전 (오류코드)
// 작가 상세 페이지
@GetMapping({"/authorDetail", "/authorModify"})
public void authorGetInfoGET(int authorId, Criteria cri, Model model) throws Exception{
log.info("authorDetail..." + authorId);
// 페이지 정보
model.addAttribute("cri" + cri);
// 선택 작가 정보
model.addAttribute("authorInfo", authorservice.authorGetDetail(authorId));
}
// 변경후
// 작가 상세 페이지
@GetMapping({"/authorDetail", "/authorModify"})
public void authorGetInfoGET(int authorId, @ModelAttribute("cri") Criteria cri, Model model) throws Exception{
log.info("authorDetail..." + authorId);
// 페이지 정보
// model.addAttribute("cri" + cri);
// 선택 작가 정보
model.addAttribute("authorInfo", authorservice.authorGetDetail(authorId));
}
@ModelAddAttribute 와 model.addattribute의 차이점
'오류 및 편의성 모음' 카테고리의 다른 글
Comments