[B -2-29] Ajax 댓글 처리 2

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

반응형

댓글 등록

 

src/main/java

com.spms.mapper

ReplyMapper.java

insert()

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

import com.spms.domain.ReplyVO;

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

 


src/main/resources

com

spms

mapper

ReplyMapper.xml

insert()

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

</mapper>

 


src/test/java

com.spms.mapper

ReplyMapperTests.java

testCreate()

...더보기
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);
	}
	
	@Test
	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);
		});
	}
}

 

ReplyMapperTests 내부의 bnoArr게시물 번호의 일부로 실제 데이터베이스에 있는 번호여야만 합니다.

(PKFK관계로 묶여있기 때문에)

 

 


댓글 등록 유닛 테스트

 

댓글 등록 작업이 완료된 것을 확인.

...더보기
select * 
from TBL_REPLY
order by RNO desc;

 

 

 

반응형

'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-30] Ajax 댓글 처리 3  (0) 2019.10.06
[B -2-28] Ajax 댓글 처리 1  (0) 2019.10.04
[B -2-27] REST 방식으로 전환  (0) 2019.10.04