-
변수에 null 값이 들어갈 때 생기는 오류 ( java.lang.NumberFormatException )기타 2023. 4. 12. 12:41
WARN : org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver - Failed to bind request element: org.springframework.web.method.annotation.MethodArgumentTypeMismatchException: Failed to convert value of type 'java.lang.String' to required type 'int'; nested exception is java.lang.NumberFormatException: For input string: "undefined"
댓글을 삭제한 후, list를 불러오지 못하고 해당 오류가 발행했다.
function add(reply){ // add함수 선언 시작 console.log(reply); $.ajax({ type:"post", // method방식(get, post, put, delete) url:"/replies/new", data:JSON.stringify(reply), contentType:"application/json; charset=utf-8", success:function(result){ if(result=="success"){ alert("댓글쓰기 성공") list({board_no:reply.board_no,page:reply.page}) } } }) }
해당 함수의 마지막 부분에 list 를 page 요소 없이 호출했더니, 해당 에러가 발생했다, list 함수는 board_no 와 page 요소를 받아야하는데 page 요소가 없어서 자동적으로 java.lang.NumberFormatException 예외 처리됐고, 그 결과 page에는 String 타입인 undefined 로 저장됐다.
또한, page 요소는 MODEL 에 int로 선언되어 있기 때문에, string타입인 undefined를 저장할 수 없어서 에러가 발생했다.
** 변수의 값이 주어지지 않았을 때 발행하는 예외처리와 그에 따라 발생할 수 있는 오류에 대해 공부할 수 있었다.
'기타' 카테고리의 다른 글
org.springframework.beans.factory.BeanCreationException (0) 2023.04.18 게시판 번호 설정 (SelectKey 지정 에러) (0) 2023.04.14 css 블록 height 지정 팁 (0) 2023.04.12 링크 모음 (0) 2023.04.06 HTTP 상태 415 – 지원되지 않는 Media Type (0) 2023.04.05