• 로그인
  • 장바구니에 상품이 없습니다.

home2 게시판 Spring 게시판 댓글기능 return 값

댓글기능 return 값

3 글 보임 - 1 에서 3 까지 (총 3 중에서)
  • 글쓴이
  • #132562

    황승현
    참가자
    (CommentController.java)
    @PostMapping("/reply")
    String addReply(String content, Long id, Authentication auth) {
      commentService.saveComment(content, id, auth);
      return "redirect:/detail/";
    }
    (CommentService.java)
    public void saveComment(String content, Long id, Authentication auth) {
      Comment comment = new Comment();
      comment.setContent(content);
      comment.setParentId(id);
      comment.setUsername(auth.getName());
      commentRepository.save(comment);
    }
    
    영상 보기 전 댓글 기능 만들어봤습니다. 기능은 잘 구현되나 강의에서 redirect를 영상에서 list페이지로 하셨는데 현재 페이지를 redirect 하고 싶었습니다. return "redirect:/detail/id"; 를 하고 싶습니다. 그래도 적으니까
    Bad Request
    /detail/id
    Failed to convert value of type 'java.lang.String' to required type 'java.lang.Long'; For input string: "id"
    라는 에러가 나옵니다. return 뒤 큰 따옴표 안에 addReply의 파라미터 id를 넣고 싶습니다. return 뒤 큰따옴표에 변수를 어떻게 넣나요? 찾아봐도 안 나오네요..
    #132568

    codingapple
    키 마스터
    문자에 변수넣으려면 "redirect:/detail/" + 변수명 해봅시다
    #132822

    황승현
    참가자
    우와 된다! 고맙습니다!
     
3 글 보임 - 1 에서 3 까지 (총 3 중에서)
  • 답변은 로그인 후 가능합니다.

About

현재 월 700명 신규수강중입니다.

  (09:00~20:00) 빠른 상담은 카톡 플러스친구 코딩애플 (링크)
  admin@codingapple.com
  이용약관
ⓒ Codingapple, 강의 예제, 영상 복제 금지
top

© Codingapple, All rights reserved. 슈퍼로켓 에듀케이션 / 서울특별시 강동구 고덕로 19길 30 / 사업자등록번호 : 212-26-14752 온라인 교육학원업 / 통신판매업신고번호 : 제 2017-서울강동-0002 호 / 개인정보관리자 : 박종흠