Notice
Recent Posts
Recent Comments
Link
«   2024/07   »
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
Archives
Today
Total
관리 메뉴

KSI일기장

spring에러 MethodArgumentTypeMismatchException,NumberFormatException 본문

Spring

spring에러 MethodArgumentTypeMismatchException,NumberFormatException

MyDiaryYo 2023. 5. 9. 16:02

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: "delete"

 

Caused by: java.lang.NumberFormatException: For input string: "delete"

For input string: "delete" -> 으로 봤을 때 delete 가 버튼이 잘못 되있는것으로 예상되어 확인해보니

jsp 에서  delete button 경로가 지정 되있지 않았었습니다

 

수정 전:

<button id="deleteBtn" >삭제</button>

첫번째 수정:

<button id="deleteBtn" onclick="location.href='../../delete/${boardCode}/${detail.boardNo}'">삭제</button>

 

-> 삭제는 되나 js가 안먹는다 (js confirm창 작동 x) -> js 에서 boardCode를 못 읽는 것으로 보여진다

js

// 즉시 실행 함수 : 성능up, 변수명 중복 X
(function(){
    const deleteBtn = document.getElementById("deleteBtn"); // 존재하지 않으면 null

    if(deleteBtn != null){ // 버튼이 화면에 존재할 때
        deleteBtn.addEventListener("click", function(){
            // 현재 : /board/detail/{boardCode}/{boardNo}
            // 목표 : /board/delete/{boardCode}/{boardNo}

            let url = contextPath + "/board/delete/" + boardCode + "/" +  boardNo;
            // 삭제 성공 -> 해당 게시판 목록 조회 1페이지로 리다이렉트
            // 삭제 실패 -> 요청 이전 페이지(referer)로 리다이렉트

            // UPDATE BOARD SET
            // BOARD_ST = 'Y'
            // WHERE BOARD_NO = #{boardNo}


            if( confirm("정말로 삭제 하시겠습니까?") ){
                location.href = url; // get방식으로 url에 요청
            }

        });
    }

})();

 

두번째 수정: 수정 전으로 복귀

<button id="deleteBtn" >삭제</button>

 

-> jsp에 제일 하단에 boardCode 선언 해주니 js 작동되는거 확인

<script>
        // 댓글 관련 JS 코드에 필요한 값을 전역 변수로 선언

        // jsp 파일 : html, css, js, el, jstl 사용 가능
        // js  파일 : js

        // 코드 해석 순서  :   EL == JSTL > HTML > JS

        // ** JS 코드에서 EL/JSTL을 작성하게 된다면 반드시 ""를 양쪽에 추가 **

        // 최상위 주소
        const contextPath = "${contextPath}";
        
        // 게시글 번호
        const boardNo = "${detail.boardNo}"; // "500"

        // 로그인한 회원 번호
        const loginMemberNo = "${loginMember.memberNo}";
        // -> 로그인 O  : "10";
        // -> 로그인 X  : "";  (빈문자열)

       // 게시판 번호
		const boardCode = "${boardCode}";
        
    </script>