当前位置: 首页> 财经> 创投人物 > 公司注册资金实缴新政策出台2024_网页美工实训结论与心得体会_百度ai人工智能平台_广州:推动优化防控措施落

公司注册资金实缴新政策出台2024_网页美工实训结论与心得体会_百度ai人工智能平台_广州:推动优化防控措施落

时间:2025/8/2 8:47:00来源:https://blog.csdn.net/2301_80114420/article/details/143981934 浏览次数:0次
公司注册资金实缴新政策出台2024_网页美工实训结论与心得体会_百度ai人工智能平台_广州:推动优化防控措施落
动态 Sql 是指 MyBatis Sql 语句进行灵活操作,通过表达式进行判断,对 Sql 进行灵活拼接、组装。
例如:
  • 我们要查询姓名中带 M 和 高于 1000的员工信息;
  • 可能有时候我们需要不带条件查询;
  • 可能有时候我们需要模糊查询;
  • 可能有时候需要根据多条件查询;
  • 动态SQL可以帮助我们解决这些问题。
  • 通过Mybatis提供的各种标签方法实现动态拼接sql

if标签

mapper文件:

<select id = "selectUseIf" parameterType = "com.gs.entity.Emp"
resultType = "com.gs.entity.Emp" >
select empno,ename,job,mgr,hiredate,sal,comm,deptno from emp
where
<!--
注意:判断条件中使用的变量为实体类或输入参数的属性
空字符串的判断仅能使用在字符串类型的属性中
-->
<if test = "ename != null and ename != ''" >
ename like concat('%',#{ename},'%')
</if>
<if test = "sal != null" >
and sal=#{sal}
</if>
<if test = "deptno != null" >
and deptno=#{deptno}
</if>
</select>

测试:
<select id = "selectUseIf" parameterType = "com.gs.entity.Emp"
resultType = "com.gs.entity.Emp" >
select empno,ename,job,mgr,hiredate,sal,comm,deptno from emp
where
<!--
注意:判断条件中使用的变量为实体类或输入参数的属性
空字符串的判断仅能使用在字符串类型的属性中
-->
<if test = "ename != null and ename != ''" >
ename like concat('%',#{ename},'%')
</if>
<if test = "sal != null" >
and sal=#{sal}
</if>
<if test = "deptno != null" >
and deptno=#{deptno}
</if>
</select>

where标签

mapper文件:

<select id = "selectUseWhere" parameterType = "com.gs.entity.Emp"
resultType = "com.gs.entity.Emp" >
select empno,ename,job,mgr,hiredate,sal,comm,deptno from emp
<where>
<if test = "ename != null and ename != ''" >
ename like concat('%',#{ename},'%')
</if>
<if test = "sal != null" >
and sal=#{sal}
</if>
<if test = "deptno != null" >
and deptno=#{deptno}
</if>
</where>
</select>
测试:
@Test
public void testWhere () {
SqlSession sqlSession = MybatisUtil . getSession ();
EmpMapper empMapper = sqlSession . getMapper ( EmpMapper . class );
Emp emp = new Emp ();
emp . setEname ( "S" );
emp . setSal ( 1300.0 );
emp . setDeptno ( 20 );
List < Emp > list = empMapper . selectUseWhere ( emp );
for ( Emp e : list ) {
System . out . println ( e );
}
sqlSession . close ();
}
关键字:公司注册资金实缴新政策出台2024_网页美工实训结论与心得体会_百度ai人工智能平台_广州:推动优化防控措施落

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: