๊ด€๋ฆฌ ๋ฉ”๋‰ด

Coding Planet

[MyBatis] test์˜ ์ˆซ์ž, ๋ฌธ์ž์—ด ๋น„๊ต (ํฐ ๋”ฐ์˜ดํ‘œ, ์ž‘์€ ๋”ฐ์˜ดํ‘œ ๊ตฌ๋ถ„ ๊ผญ!!!!!) ๋ณธ๋ฌธ

๐ŸŒฑSPRING

[MyBatis] test์˜ ์ˆซ์ž, ๋ฌธ์ž์—ด ๋น„๊ต (ํฐ ๋”ฐ์˜ดํ‘œ, ์ž‘์€ ๋”ฐ์˜ดํ‘œ ๊ตฌ๋ถ„ ๊ผญ!!!!!)

jhj.sharon 2023. 11. 14. 13:25
๋ฐ˜์‘ํ˜•

 

๊ฒŒ์‹œํŒ์˜ ๊ฒ€์ƒ‰๊ธฐ๋Šฅ์„ ๊ตฌํ˜„ํ•˜๋ฉด์„œ ํ•„ํ„ฐ๋ง์ด ์•ˆ๋˜๋Š” ๋ฌธ์ œ๊ฐ€ ์žˆ์—ˆ๋‹ค. ์ด๊ฒƒ์ €๊ฒƒ ํ•ด๋ณด๊ณ  ์‹ฌ์ง€์–ด chatGPTํ•œํ…Œ๋„ ๋ฌผ์–ด๋ณด๊ณ  ๋‚œ๋ฆฌ๋ฅผ ์ณค์ง€๋งŒ ๊ทธ ์›์ธ์„ ์•Œ ์ˆ˜ ์—†์—ˆ๋‹ค.

ํŒŒ๋ผ๋ฏธํ„ฐ๋“ค๋„ ์ •์ƒ์ ์œผ๋กœ ๋“ค์–ด์˜ค๊ณ  ์žˆ์—ˆ๊ธฐ ๋•Œ๋ฌธ์— sql์—์„œ ํ•„ํ„ฐ๋ง์ด ์•ˆ๋˜๋Š” ๋ฌธ์ œ์ธ ๊ฒƒ ๊ฐ™์•„์„œ ์ฟผ๋ฆฌ๋ฌธ์„ ์œ ์‹ฌํžˆ ๋ณด๋˜ ๋„์ค‘ test ์กฐ๊ฑด์— ๋Œ€ํ•œ ์˜ค๋ฅ˜๋ฅผ ๋ฐœ๊ฒฌํ–ˆ๋‹ค.

 

 

1. ๊ธฐ์กด ์ฟผ๋ฆฌ: ํ•„ํ„ฐ๋ง ์•ˆ๋จ

  • ๋ฌธ์ œ์˜ ์›์ธ์€ <when test="searchCondition == '0'"> ์กฐ๊ฑด์— ๋ฌธ์ œ๊ฐ€ ์žˆ์—ˆ๋‹ค. test ์ดํ•˜ ์กฐ๊ฑด์„ ์ž‘์€ ๋”ฐ์˜ดํ‘œ(' ')๋กœ ๊ฐ์‹ธ๊ณ  ๋น„๊ต๋Œ€์ƒ ๋ฌธ์ž์—ด์„ ํฐ ๋”ฐ์˜ดํ‘œ(" ")๋กœ ๊ฐ์‹ธ์คฌ์–ด์•ผํ•˜๋Š”๋ฐ ๋ฐ˜๋Œ€๋กœ ํ•œ ๊ฒƒ์ด๋‹ค.
 <select id="selectBoardList" parameterType="NoticeBoardVO" resultMap="NoticeBoardList">
        select
        row_number() over (order by notice_board_no) as rownum,
        notice_board_no,
        notice_board_type,
        notice_board_sub_type,
        notice_title,
        notice_first_regist_dtm,
        notice_ans_yn,
        notice_wrtr,
        notice_view_count,
        notice_cat
        from
        tb_notice_board
        where notice_del_yn = 'N'
        and notice_board_sub_type = #{noticeBoardSubType}
        <choose>
            <when test="searchCondition == '0'">
                and notice_title like '%'||#{searchKeyword}||'%'
            </when>
            <when test="searchCondition == '1'">
                and notice_contents like '%'||#{searchKeyword}||'%'
            </when>
            <when test="searchCondition == '2'">
                and notice_wrtr like '%'||#{searchKeyword}||'%'
            </when>
            <otherwise>
                <!-- ์•„๋ฌด ์กฐ๊ฑด๋„ ์—†์ด ์ „์ฒด ๋ชฉ๋ก์„ ์ถœ๋ ฅ -->
            </otherwise>
        </choose>

        order by
        notice_board_no DESC
        limit CAST(#{recordCountPerPage} AS INTEGER) offset CAST(#{firstIndex} AS INTEGER)

    </select>

 

 

 

 

2. ์ˆ˜์ •๋œ ์ฟผ๋ฆฌ : ์‹คํ–‰ ์ž˜ ๋จ!

 

<!--๋ชฉ๋ก ์ถœ๋ ฅ -->
<select id="selectBoardList" parameterType="NoticeBoardVO" resultMap="NoticeBoardList">
    select
    row_number() over (order by notice_board_no) as rownum,
    notice_board_no,
    notice_board_type,
    notice_board_sub_type,
    notice_title,
    notice_first_regist_dtm,
    notice_ans_yn,
    notice_wrtr,
    notice_view_count,
    notice_cat
    from
    tb_notice_board
    where notice_del_yn = 'N'
    and notice_board_sub_type = #{noticeBoardSubType}
    <choose>
        <when test='searchCondition =="0"'>
            and notice_title like '%'||#{searchKeyword}||'%'
        </when>
        <when test='searchCondition == "1"'>
            and notice_contents like '%'||#{searchKeyword}||'%'
        </when>
        <when test='searchCondition == "2"'>
            and notice_wrtr like '%'||#{searchKeyword}||'%'
        </when>
        <otherwise>
            <!-- ์•„๋ฌด ์กฐ๊ฑด๋„ ์—†์ด ์ „์ฒด ๋ชฉ๋ก์„ ์ถœ๋ ฅ -->
        </otherwise>
    </choose>
๋ฐ˜์‘ํ˜•
Comments