[B -2-30] Ajax 댓글 처리 3

2019. 10. 6. 20:49Project B (SPMS)/Project B 파트5

반응형

댓글 조회

 

src/main/java

com.spms.mapper

ReplyMapper.java 인터페이스

read()

 

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

import com.spms.domain.ReplyVO;

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

 


src/main/resources

com

spms

mapper

ReplyMapper.xml

read()

 

...더보기
<?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>
	
</mapper>

 

 

 


src/test/java

com.spms.mapper

ReplyMapperTests.java

testRead()

 

...더보기
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);
		});
	}
	
	@Test
	public void testRead() {
		Long targetRno = 5L;
		ReplyVO replyVO = replyMapper.read(targetRno);
		log.info(replyVO);
	}
}

 

존재하는 댓글 번호 (targetRno) 중에서 한 개를 정해서 확인한다.

여기서는 댓글 번호 5를 조회한다.


댓글 조회 유닛 테스트

 

...더보기
|----|-------|----------|--------|----------------------|----------------------|
|rno |bno    |reply     |replyer |replydate             |updatedate            |
|----|-------|----------|--------|----------------------|----------------------|
|5   |524310 |댓글 테스트! 3 |작성자3    |2019-10-06 20:15:44.0 |2019-10-06 20:15:44.0 |
|----|-------|----------|--------|----------------------|----------------------|

 

반응형

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

[B -2-32] Ajax 댓글 처리 5  (0) 2019.10.06
[B -2-31] Ajax 댓글 처리 4  (0) 2019.10.06
[B -2-29] Ajax 댓글 처리 2  (0) 2019.10.06
[B -2-28] Ajax 댓글 처리 1  (0) 2019.10.04
[B -2-27] REST 방식으로 전환  (0) 2019.10.04