[B -2-31] Ajax 댓글 처리 4

2019. 10. 6. 21:05Project B (SPMS)/Project B 파트5

반응형

댓글 삭제

 

src/main/java

com.spms.mapper

ReplyMapper.java 인터페이스

delete()

 

...더보기
package com.spms.mapper;

import com.spms.domain.ReplyVO;

public interface ReplyMapper {
	public int insert(ReplyVO vo);
	public ReplyVO read(Long bno);
	public int delete(Long rno);
}

 

특정 댓글의 삭제 댓글의 번호(rno)만으로 처리 가능하다.


src/main/resources

com

spms

mapper

ReplyMapper.xml

delete()

 

...더보기
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
  PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.spms.mapper.ReplyMapper">
	
	<insert id="insert">
		insert into TBL_REPLY (
			RNO, BNO, REPLY, REPLYER
		)
		values (
			SEQ_REPLY.NEXTVAL, #{bno}, #{reply}, #{replyer}
		)
	</insert>
	
	<select id="read" resultType="com.spms.domain.ReplyVO">
		select *
		from TBL_REPLY
		WHERE RNO = #{rno}
	</select>
	
	<delete id="delete">
		delete from TBL_REPLY
		where RNO = #{rno}
	</delete>
	
</mapper>

 

 


 

src/test/java

com.spms.mapper

ReplyMapperTests.java

testDelete()

 

...더보기
package com.spms.mapper;

import java.util.stream.IntStream;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import com.spms.domain.ReplyVO;

import lombok.Setter;
import lombok.extern.log4j.Log4j;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {com.spms.config.RootConfig.class} )
@Log4j
public class ReplyMapperTests {

	private Long[] bnoArr = { 524313L, 524312L, 524311L, 524310L, 524309L };
	
	@Setter(onMethod_ = @Autowired)
	private ReplyMapper replyMapper;
	
	
	public void testMapper() {
		log.info(replyMapper);
	}
	
	
	public void testCreate() {
		IntStream.rangeClosed(1, 10).forEach(i -> {
			ReplyVO replyVO = new ReplyVO();
			replyVO.setBno(bnoArr[i % 5]);
			replyVO.setReply("댓글 테스트! " + i);
			replyVO.setReplyer("작성자" + i);
			replyMapper.insert(replyVO);
		});
	}
	
	
	public void testRead() {
		Long targetRno = 5L;
		ReplyVO replyVO = replyMapper.read(targetRno);
		log.info(replyVO);
	}
	
	@Test
	public void testDelete() {
		Long targetRno = 7L;
		replyMapper.delete(targetRno);
	}
	
}

 

삭제할 댓글 번호(targetRno)를 지정한다.


 

댓글 삭제 유닛 테스트

 

...더보기
INFO : jdbc.sqlonly - delete from TBL_REPLY where RNO = 7 

 

반응형

'Project B (SPMS) > Project B 파트5' 카테고리의 다른 글

[B -2-33] Ajax 댓글 처리 6  (0) 2019.10.06
[B -2-32] Ajax 댓글 처리 5  (0) 2019.10.06
[B -2-30] Ajax 댓글 처리 3  (0) 2019.10.06
[B -2-29] Ajax 댓글 처리 2  (0) 2019.10.06
[B -2-28] Ajax 댓글 처리 1  (0) 2019.10.04