Mybatis 映射文件
//常规查询
@Select("select * from user where id = #{id}")
User findById(@Param("id") long id);
@Select("select * from user where name = #{name}")
User findByName(@Param("name") String name);
//Mybatis用${column}进行字符串替换,一句即可替代多句SQL查询语句
@Select("select * from user where ${column} = #{value}")
User findByColumn(@Param("column") String column, @Param("value") String value);
缓存
- 默认开启一级缓存,只对一个会话中的数据进行缓存
- 开启二级缓存,SQL映射文件中添加
<cache/> 标签
动态SQL
- if
- choose (when, otherwise)
- trim (where, set)
相关文章:
-
2021-10-19
-
2022-12-23
-
2021-11-06
-
2021-12-13
-
2021-07-08
-
2021-05-23