마이바티스 selectKey

Web Development assistant·2022년 3월 19일
0

# SQL

목록 보기
9/28
<insert id="insertSelectKey">
	<selectKey order="BEFORE" keyProperty="bno" resultType="long">
			select seq_board.nextval from dual
	</selectKey>
		insert into 
			tbl_board(bno, title, content, writer) 
		values(#{bno}, #{title}, #{content}, #{writer})
	</insert>
    
    
    
    
    
    @Test
	public void insertSelectKey() {
		BoardVO board = new BoardVO();
		board.setTitle("bb");
		board.setContent("bbContent");
		board.setWriter("jiseong");
		int result = mapper.insertSelectKey(board);
		System.out.println(">>> "+ result); 		// 추가된 행 수 : 1
		System.out.println(">>> "+ board.getBno());	// 마지막 글 번호 : 6
	}

result 에 담겨지는것은 추가된 행의 수 insert= 1;
객체에 담겨지는것이 마지막 글 번호가 된다.

0개의 댓글