2022년 11월 15일 - Spring 댓글 2

kangsun·2022년 11월 15일
0

Spring

목록 보기
12/24

detail.jsp - front단에 출력해주기

  • 댓글 내용 부분을 div로 감싸준다.

    content 부분을 <div></div> 블럭으로 감싸주어야한다.
    댓글마다 내용이 다르기 때문에 cno로 번호를 붙여줘서 하나씩 수정할 수 있도록 설정해준다.


  • 댓글 작성자 정보와 작성일, 수정삭제 을 div로 감싸준다.
    → 수정버튼을 누르면 댓글번호(cno)와 댓글내용(coment)을 가져가야 한다.

    변수로 넘어온 cno를 자바스크립트 수정/삭제에 담아줘야 해당 댓글'만' 수정/삭제를 해줄 수 있다.


    개발자모드로 each반복문 적용되었는지 확인

		//댓글 목록
		function commentList(){
			$.ajax({
				     url: '/comment/list'
				   , type:'get'
				   , data:{'pno': pno} 		 // let pno = "${product.PRODUCT_CODE}"; //부모글 번호
				   , success:function(data){
					   //alert(data);	//[object Object],[object Object],[object Object],[object Object]
				  	   let a='';
					   $.each(data, function(key, value){
						   a += '<div class="commentArea" style="border-bottom:1px solid darkgray; 
						   									     margin-bottom:15px;">';
						   a += '	<div class="commentInfo' + value.cno + '">';
						   a += '		댓글번호:' + value.cno + ' /작성자 : ' + value.wname + " " + value.pno;
						   a += '		<a href="javascript:commentUpdate(' + value.cno
																+ ', \'' + value.content + '\');">수정</a>';
						   a += '		<a href="javascript:commentDelete(' + value.cno + ');">삭제</a>';
						   a += '	</div>';
						   a += '	<div class="commentContent' + value.cno + '">';
						   a += '		<p>내용 : ' + value.content + '</p>';
						   a += '		</div>';
						   a += '	</div>';
					   });//each end

				   	   $(".commentList").html(a);
				   }//success end
			});//ajax() end
		}//commentList() end

  • 댓글 수정


    댓글을 수정해주기 위해선 내용부분을 div 코드로 감싸야한다.
    그 내용을 블럭으로 감싸줘야하고, 댓글마다 내용이 다르기 때문에 cno로 번호를 붙여줘서 하나씩 수정할 수 있도록 설정해준다.

detail.jsp

1) 댓글수정 - 댓글 내용 출력을 input폼으로 변경

  • input에 content 내용 넣기
  • 텍스트 박스안에있는 내용에 cno 값을 넣어줘야 한다.
a += '		<input type="text" value="' + content + '" id="content_' + cno + '">';
  • 수정 버튼 넣기
  • 개발자모드로 값이 잘 들어가있는지 확인

  • alert 확인

  • 개발자모드로 each 반복문 적용되었는지 확인


2) 댓글수정

  • alert 확인


    값이 잘 들어온다.

  • ajax 추가


CommentCont

// ------------------------------------------------------------- update 댓글수정
	
	
	@RequestMapping("/update")
	@ResponseBody
	public int mCommentServiceUpdateProc(@PathVariable int cno, @RequestParam String content) throws Exception {
		CommentDTO comment=new CommentDTO();
		comment.setCno(cno);
		comment.setContent(content);
		return commentDao.commentUpdate(comment);
	}//Update end
	

CommentDAO

// ------------------------------------------------------------- update 댓글수정
	
	
	public int commentUpdate(CommentDTO comment) {
		return sqlSession.update("comment.update", comment);
	}//update() end
	

comment.xml


<!--     [ update 댓글수정 ]     -->

	<update id="update" parameterType="kr.co.itwill.comment.CommentDTO">
		UPDATE pcomment
		SET	   content = #{content}
		WHERE  cno = #{cno}
	</update>

  • 댓글 삭제

detail.jsp

		function commentDelete(cno) {
			
			$.ajax({
					 url     : '/comment/delete/' + cno
				   , type    : 'post'
				   , success : function(data) {
					   if(data==1){ //delete성공
						   commentList(); //댓글 삭제 후 목록으로 이동. 목록 출력
					   }//if end
				   }//seccess end
			});//ajax() end
		}//commentDelete() end

CommentCont

// ------------------------------------------------------------- delete 댓글삭제
	
	@RequestMapping("/delete/{cno}")
	@ResponseBody
	public int mCommentServiceDelete(@PathVariable int cno) throws Exception {
		return commentDao.commentDelete(cno);
	}//mCommentServiceDelete end

CommentDAO

// ------------------------------------------------------------- delete 댓글삭제
	
	public int commentDelete(int cno) throws Exception {
		return sqlSession.delete("comment.delete", cno);
	}//Delete() end

comment.xml

<!--     [ delete 댓글삭제 ]     -->

	<delete id="delete" parameterType="int">
		DELETE FROM pcomment
		WHERE cno = #{cno}
	</delete>

### 졸업작품 예매 결제할떄 마일리지, 이벤트 결제, 어떤 경로로 결제할지 ? 예매율 count 50개중 25개 백분율 계산만 하면 됨
profile
코딩 공부 💻

0개의 댓글