动态sql语句
<select id = "sysDeptList" parameterType="com.neusoft.neusoftoa.pojo.SysDept" resultType="com.neusoft.neusoftoa.pojo.SysDept">
select * from sys_dept
<where>
<if test = "deptName!=null and deptName!=''">
and dept_name like concat('%',#{deptName},'%')
</if>
<if test="status!=null and status!=''">
and status=#{status}
</if>
</where>
</select>
类似于if-else的查询,但是没有else语句,用when,otherwise来代替
<select id = "sysDeptList" parameterType="com.neusoft.neusoftoa.pojo.SysDept" resultType="com.neusoft.neusoftoa.pojo.SysDept">
select * from sys_dept
<where>
<choose>
<when test="deptName!=null and deptName!=''">
and dept_name like concat('%',#{deptName},'%')
</when>
<when test = "deptName!=null and deptName!=''">
and status=#{status}
</when>
<otherwise>
and del_flag=0
</otherwise>
</choose>
</where>
</select>
循环sql,通常涉及到批量操作,批量删除。
用update,注意foreach五件套:
1、collection=“array"或者“list”,以数组为例
2、参数起个名
3、 开始符号(
4、结束符号 )
5、分隔符号 ,