1. DAO 와 연동하기 위한 SQL 작성하기
DAO 참고자료
https://ko.wikipedia.org/wiki/%EB%8D%B0%EC%9D%B4%ED%84%B0_%EC%A0%91%EA%B7%BC_%EA%B0%9D%EC%B2%B4
1. CRUD + LIST(목록) SQL 구현
1-1 Create (게시물 작성)
(글 제목, 글 내용, 작성자 insert)
<insert id="create">
insert into tbl_board (title, content, writer)
values(#{title},#{content}, #{writer})
</insert>
1-2 Read (게시물 읽기)
(tbl_board 테이블에서 bno(글번호)를 기준으로 DB 컬럼을 READ)
<select id="read" resultType="com.myp.domain.BoardVO">
select
bno, title, content, writer, regdate, viewcnt
from
tbl_board
where bno = #{bno}
</select>
1-3. Update (게시글 수정)
(bno(글번호) 기준값으로 글 제목, 글 내용을 수정)
<update id="update">
update tbl_board set title =#{title}, content =#{content}
where bno = #{bno}
</update>
1-4. Delete(삭제)
(bno(글번호) 기준값으로 해당데이터 삭제)
1-5. ListAll(전체 글목록)
(bno(기준)으로 모든 데이터를 불러들임)
2.완성된 전체코드
<?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.myp.mapper.BoardMapper">
<insert id="create">
insert into tbl_board (title, content, writer)
values(#{title},#{content}, #{writer})
</insert>
<select id="read" resultType="com.myp.domain.BoardVO">
select
bno, title, content, writer, regdate, viewcnt
from
tbl_board
where bno = #{bno}
</select>
<update id="update">
update tbl_board set title =#{title}, content =#{content}
where bno = #{bno}
</update>
<delete id="delete">
delete from tbl_board where bno = #{bno}
</delete>
<select id="listAll" resultType="com.myp.domain.BoardVO">
<![CDATA[
select
bno, title, content, writer, regdate, viewcnt
from
tbl_board
where bno > 0
order by bno desc, regdate desc
]]>
</select>
</mapper>
'[Spring+JSP]CRUD 게시판 만들기' 카테고리의 다른 글
[스프링]MVC2방식 CRUD 게시판 만들기 6.DAO 작성 (0) | 2018.07.10 |
---|---|
[스프링]MVC2방식 CRUD 게시판 만들기 5.board-Mapper.xml 작성(심화) (0) | 2018.07.09 |
[스프링]MVC2방식 CRUD 게시판 만들기 5.VO(DTO) 생성 (0) | 2018.07.09 |
[스프링]MVC2방식 CRUD 게시판 만들기 4.DB 기초공사 (0) | 2018.07.08 |
[스프링]MVC2방식 CRUD 게시판 만들기 3.root-context.xml 설정(심화) (0) | 2018.07.08 |