mybatis-xml常用写法
批量插入
<insert >
insert into table_name (name,age,high,status,create_time,update_time)
values
<foreach collection="list" item="e" index="index" separator=",">
(
#{e.name},
#{e.age},
#{e.high},
#{e.status},
#{e.createTime},
#{e.updateTime}
)
</foreach>
</insert>
判断String类型字段并模糊查询
<if test="name != null and name != ''"> AND name LIKE CONCAT('%',#{name},'%') </if>
判断数值类型字段并精确查询,不需要加!=''
<if test="port != null"> AND port = #{port} </if>
单个字段的多值查询
<select > select * from table_name where id in <foreach collection="ids" item="id" open="(" close=")" separator=","> #{id} </foreach> </select>
自增主键id
<insert > insert into table_name(a,b,c,d) values(#{a},#{b},#{c},#{d},) </insert>