MyBatis学习总结(2)
1.6动态SQL
1.if
<!--if标签可通过test属性的表达式进行判断,若表达式的结果为true,则标签中的内容会执行;反之标签中的内容不会执行--> |
2.where
<select id="getEmpListByMoreTJ2" resultType="Emp"> |
where和if一般结合使用: |
3.trim
<select id="getEmpListByMoreTJ" resultType="Emp"> |
trim用于去掉或添加标签中的内容 |
4.choose、when、otherwise
<!--List<Emp> getEmpListByChoose(Emp emp);--> |
5.foreach
<!--int insertMoreEmp(List<Emp> emps);--> |
属性: |
6.SQL片段
<!--sql片段,可以记录一段公共sql片段,在使用的地方通过include标签进行引入--> |
1.7MyBatis的缓存
1.7.1MyBatis的一级缓存
一级缓存是SqlSession级别的,通过同一个SqlSession查询的数据会被缓存,下次查询相同的数据,就 |
1.7.2MyBatis的二级缓存
二级缓存是SqlSessionFactory级别,通过同一个SqlSessionFactory创建的SqlSession查询的结果会被 |
1.7.3二级缓存的相关配置
在mapper配置文件中添加的cache标签可以设置一些属性: |
1.7.3MyBatis缓存查询的顺序
先查询二级缓存,因为二级缓存中可能会有其他程序已经查出来的数据,可以拿来直接使用。 |
1.8MyBatis的逆向工程
正向工程:先创建Java实体类,由框架负责根据实体类生成数据库表。Hibernate是支持正向工程的。 |
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 小白条的个人博客!