<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="dao.EmpDao">
<!--查询-->
<select id="electEmpByMybatis">
select * from emp;
<where>
<if test="deptno!=null and deptno!='' ">
and deptno=#{deptno}
</if>
<if test="job!=null and job!='' ">
and job=#{job}
</if>
</where>
order by sal
/*if更简单*/
</select>
<!--根据给的deptno动态查询,如多选-->
<select id="updateEmpMybatis">
update emp set job='xxx' where empno in
<!-- <foreach collection="产参数的集合形式" item="每一次循环的变量" index="集合的小标"
open="以什么开头" close="以什么结束" separator="值之间用什么分隔"></foreach>-->
<foreach collection="list" item="empno" index="i" open="(" close=")" separator=",">
#{empno}
</foreach>
</select>
</mapper>
动态SQL在xxxMapper.xml文件中方式
最新推荐文章于 2023-10-30 14:22:11 发布