๐ ์ฌ์ฉํ SQL๋ฌธ ์ ์
<?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.ssafy.board.model.dao.BoardDao">
<resultMap type="Board" id="boardMap">
<result column="id" property="id"/>
<result column="writer" property="writer"/>
<result column="title" property="title"/>
<result column="content" property="content"/>
<result column="reg_date" property="regDate"/>
<result column="view_cnt" property="viewCnt"/>
</resultMap>
<!-- ์ ์ฒด ๊ธ ์กฐํ -->
<select id="selectAll" resultType="Board">
SELECT id, writer, content, title, view_cnt as viewCnt, date_format(reg_date, '%Y-%M-%d') as regDate
FROM board
</select>
<!-- ํ๋์ ๊ฒ์๊ธ ์กฐํ -->
<select id="selectOne" parameterType="int" resultMap="boardMap">
SELECT id, writer, content, title, view_cnt, date_format(reg_date, '%Y-%M-%d %H:%i:%s') as reg_date
FROM board
WHERE id = #{id}
</select>
<!-- ๊ฒ์๊ธ ๋ฑ๋ก -->
<insert id="insertBoard" parameterType="Board">
INSERT INTO board (title, writer, content)
VALUES (#{title}, #{writer}, #{content})
</insert>
<!-- ๊ฒ์๊ธ ์ญ์ -->
<delete id="deleteBoard" parameterType="int">
DELETE FROM board
WHERE id = #{id}
</delete>
<!-- ๊ฒ์๊ธ ์
๋ฐ์ดํธ ( ๋ฑ๋ก๋ ์ง๋ฅผ ๊ทธ๋ฅ ์์ ๋ ์ง์ฒ๋ผ ํ์ฉ์ ํด๋ณธ๋ค ) -->
<update id="updateBoard" parameterType="Board">
UPDATE board
SET title = #{title}, content = #{content}, reg_date = now()
WHERE id = #{id}
</update>
<!-- ์กฐํ์ ์ฆ๊ฐ -->
<update id="updateViewCnt" parameterType="int">
UPDATE board
SET view_cnt = view_cnt + 1
WHERE id = #{id}
</update>
</mapper>