본문 바로가기
CLASS/SPRING,JSTL

☀ mybatis - mapper ☀

by hingu 2024. 7. 25.

  👀 SELECT  

<!-- select list -->
<select id="point_select" resultType="pointdao">
    select * from userpoint order by uidx desc
</select>

<!-- select one -->
<select id="point_one" resultType="pointdao">
    select * from userpoint where uidx=#{aa} order by uidx desc
</select>

<!-- count  -->
<select id="ajax_select" resultType="String">
    select count(*) as ctn from rainfall where today=#{today}
</select>

<!-- 동적query -->
<select id="notice_search" resultType="noticeDAO" parameterType="Map">
    select * from notice 
    <where>
        <if test="search_part==0"> <!-- 제목+내용으로 검색할 경우  -->
            n_subject like concat('%',#{search_word},'%') or
            n_text like concat('%',#{search_word},'%')
        </if>
        <if test="search_part==1"> <!-- 제목으로 검색할 경우  -->
            n_subject like concat('%',#{search_word},'%')
        </if>
        <if test="search_part==2"> <!-- 글쓴이로 검색할 경우  -->
            n_title = #{search_word}
        </if>
    </where>
     order by nidx desc;
</select>

 

 

  👀 INSERT  

<insert id="coupon_insert">
    insert into coupon (cidx,cpname,cprate,cpuse,cpdate,indate)
    values ('0',#{cpname},#{cprate},#{cpuse},#{cpdate},now())
</insert>

 

 

  👀 UPDATE  

<update id="rainfall_update" parameterType="Object">
    update rainfall set 
    area_part1=#{area_part1},
    area_part2=#{area_part2},
    area_part3=#{area_part3},
    area_part4=#{area_part4},
    area_part5=#{area_part5} where ridx=#{ridx}
</update>

  👀 DELETE  

<delete id="rainfall_delete">
    delete from rainfall where ridx=#{del} order by ridx desc
</delete>