2019. 4. 18. 10:50ㆍMybatis
# MemberMapper.xml
<select id="selectMemberByConditionIF" parameterType="member" resultType="member">
select * from member <choose> <when test="id != null"> where id = #{id} </when> <when test="name != null"> where name = #{name} </when> </choose> </select>
<select id="selectMemberByConditionForeach" parameterType="hashmap" resultType="member">
select * from member <trim prefix="WHERE"> <if test="names != null">
<foreach collection="names" item ="names" index="index" open="(" close=")" separator=","> #{name} </foreach> </if> </trim> </select>
<select id="selectMemberByConditionTrim" parameterType="member" resultType="member">
select * from member
<trim prefix="WHERE" prefixOverrides="AND | OR"> <if test="id != null"> id = #{id} </if> <if test="name != null"> AND name = #{name} </if> </trim> </select>
<update id="updateMemberByCondition" parameterType="member">
UPDATE member
<trim prefix="SET" suffixOverrides=","> <if test="password != null"> password = #{password}, </if> <if test="name != null"> name = #{name} </if> </trim> password = #{password}, name = #{name} WHERE id = #{id} </update> |
'Mybatis' 카테고리의 다른 글
Mybatis#3) 예제 : 복수변수 ,Map변수 (0) | 2019.04.17 |
---|---|
Mybatis#2 : 예제(insert, update, select, delete..) (1) | 2019.04.16 |
MyBatis 사용하기 : DB연결 (0) | 2019.04.16 |