<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="com.demo1.board.domain.BoardMapper">

    <insert id="insertBulk" parameterType="com.demo1.board.domain.Board" >
        INSERT INTO BOARD (TITLE, CONTENT, SYS_INSERT_DTM, SYS_UPDATE_DTM)
        VALUES 
        <foreach collection="list" index="index" item="item" separator=",">
        (#{item.title}, #{item.content}, #{item.sysInsertDtm}, #{item.sysUpdateDtm})
        </foreach>
    </insert>

    <!-- Create -->
    <insert id="insertBoard" parameterType="com.demo1.board.domain.Board" useGeneratedKeys="true" keyProperty="id">
        INSERT INTO BOARD (TITLE, CONTENT, SYS_INSERT_DTM, SYS_UPDATE_DTM)
        VALUES (#{title}, #{content}, #{sysInsertDtm}, #{sysUpdateDtm})
    </insert>

    <!-- Read -->
    <select id="getBoardById" parameterType="long" resultType="com.demo1.board.domain.Board">
        SELECT *
        FROM board
        WHERE id = #{id}
    </select>

    <select id="getAllBoards" resultType="com.demo1.board.domain.Board">
        SELECT *
        FROM board
    </select>
    
    <select id="getPage" resultType="com.demo1.board.domain.Board">
        SELECT *
        FROM board
    </select>

    <!-- Update -->
    <update id="updateBoard" parameterType="com.demo1.board.domain.Board">
        UPDATE board
        SET
            title = #{title},
            content = #{content},
            sys_insert_dtm = #{sysInsertDtm},
            sys_update_dtm = #{sysUpdateDtm}
        WHERE
            id = #{id}
    </update>

    <!-- Delete -->
    <delete id="deleteBoard" parameterType="long">
        DELETE FROM board
        WHERE id = #{id}
    </delete>
</mapper>
