1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
<mapper namespace= "com.bjsxt.mapper.UserMapper" > <select id= "selByCondition" resultType= "user" > select * from tb_user <where> < if test= "id != null" > and id=#{id} </ if > < if test= "username != null and username != ''" > and username=#{username} </ if > < if test= "age != null" > and age <> #{age} </ if > <choose> <when test= "birthday != null and birthday != ''" > and birthday = #{birthday} </when> <otherwise> and birthday is null </otherwise> </choose> </where> </select> </mapper> |
1
2 3 4 5 6 7 8 9 |
<select id= "sel2" resultType= "user" > <include refid= "base_sql" /> <where> < if test= "realname != null and realname != ''" > <bind name= "realname" value= "'%' + realname + '%'" /> and realname like #{realname} </ if > </where> </select> |
1
2 3 4 5 6 7 8 9 10 11 12 13 14 |
<sql id= "base_sql" > select id, username, password, realname, age, birthday, reg_time regTime from tb_user </sql> <select id= "sel2" resultType= "user" > <include refid= "base_sql" /> <where> < if test= "realname != null and realname != ''" > <bind name= "realname" value= "'%' + realname + '%'" /> and realname like #{realname} </ if > </where> </select> |
1
2 3 4 5 6 7 8 9 10 11 12 13 14 |
<update id= "upd" > update tb_user <set> < if test= "username != null and username != ''" > username=#{username}, </ if > < if test= "age != null" > age=#{age} </ if > </set> where id=#{id} </update> |
1
2 3 4 5 6 7 8 9 |
< delete id= "delBatch" > delete from tb_user < where > id in <foreach collection= "ids" item= "id" open = "(" close = ")" separator= "," > #{id} </foreach> </ where > </ delete > |
1
2 3 4 5 6 7 8 |
< insert id= "insBatch" > insert into tb_user values <foreach collection= "users" item= "user" separator= "," > <trim prefix= "(" prefixOverrides= "," suffix= ")" suffixOverrides= "," > , default , #{ user .username}, #{ user . password }, #{ user .realname}, #{ user .age}, #{ user .birthday}, now(), </trim> </foreach> </ insert > |
1
2 |
select * from employee where empno= 'abc' select * from employee where empno= '12' |
相关文章