122 lines
3.5 KiB
XML
122 lines
3.5 KiB
XML
<?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="sgis.board.mapper.PostMapper">
|
|
|
|
<resultMap id="postResultMap" type="sgis.board.entity.Post">
|
|
<id property="postId" column="post_id"/>
|
|
<result property="boardCategoryId" column="board_category_id"/>
|
|
<result property="parentPostId" column="parent_post_id"/>
|
|
<result property="userNo" column="user_no"/>
|
|
<result property="title" column="title"/>
|
|
<result property="content" column="content"/>
|
|
<result property="viewCount" column="view_count"/>
|
|
<result property="status" column="status"/>
|
|
<result property="createdAt" column="created_at"/>
|
|
<result property="updatedAt" column="updated_at"/>
|
|
</resultMap>
|
|
|
|
<select id="selectPostById" parameterType="long" resultMap="postResultMap">
|
|
SELECT
|
|
post_id,
|
|
board_category_id,
|
|
parent_post_id,
|
|
user_no,
|
|
title,
|
|
content,
|
|
view_count,
|
|
status,
|
|
created_at,
|
|
updated_at
|
|
FROM
|
|
public.tb_post
|
|
WHERE
|
|
post_id = #{postId}
|
|
</select>
|
|
|
|
<select id="selectAllPosts" resultMap="postResultMap">
|
|
SELECT
|
|
post_id,
|
|
board_category_id,
|
|
parent_post_id,
|
|
user_no,
|
|
title,
|
|
content,
|
|
view_count,
|
|
status,
|
|
created_at,
|
|
updated_at
|
|
FROM
|
|
public.tb_post
|
|
ORDER BY
|
|
created_at DESC
|
|
</select>
|
|
|
|
<select id="selectPostsByBoardCategoryId" parameterType="int" resultMap="postResultMap">
|
|
SELECT
|
|
post_id,
|
|
board_category_id,
|
|
parent_post_id,
|
|
user_no,
|
|
title,
|
|
content,
|
|
view_count,
|
|
status,
|
|
created_at,
|
|
updated_at
|
|
FROM
|
|
public.tb_post
|
|
WHERE
|
|
board_category_id = #{boardCategoryId}
|
|
ORDER BY
|
|
created_at DESC
|
|
</select>
|
|
|
|
<insert id="insertPost" parameterType="sgis.board.entity.Post" useGeneratedKeys="true" keyProperty="postId">
|
|
INSERT INTO public.tb_post (
|
|
board_category_id,
|
|
parent_post_id,
|
|
user_no,
|
|
title,
|
|
content,
|
|
view_count,
|
|
status
|
|
) VALUES (
|
|
#{boardCategoryId},
|
|
#{parentPostId, jdbcType=INTEGER}, <!-- parent_post_id에 명시적으로 INTEGER JDBC 타입 지정 -->
|
|
#{userNo},
|
|
#{title},
|
|
#{content},
|
|
#{viewCount},
|
|
#{status}
|
|
)
|
|
</insert>
|
|
|
|
<update id="updatePost" parameterType="sgis.board.entity.Post">
|
|
UPDATE public.tb_post
|
|
SET
|
|
board_category_id = #{boardCategoryId},
|
|
parent_post_id = #{parentPostId, jdbcType=INTEGER}, <!-- null 허용 및 INTEGER 타입 명시 -->
|
|
user_no = #{userNo},
|
|
title = #{title},
|
|
content = #{content},
|
|
status = #{status}
|
|
WHERE
|
|
post_id = #{postId}
|
|
</update>
|
|
|
|
<delete id="deletePost" parameterType="long">
|
|
DELETE FROM public.tb_post
|
|
WHERE post_id = #{postId}
|
|
</delete>
|
|
|
|
<update id="incrementViewCount" parameterType="long">
|
|
UPDATE public.tb_post
|
|
SET
|
|
view_count = view_count + 1
|
|
WHERE
|
|
post_id = #{postId}
|
|
</update>
|
|
|
|
</mapper>
|