mybatis 入门下

来源:互联网 发布:java 文件迁移 编辑:程序博客网 时间:2024/05/29 06:28

1标签

if标签的使用 test后面加OGNLB表达式 c:if test从参数取值判断
<select id="getEmpByConditionIf" resultType="emp">
select *from tabl_emple where 
<if test="id!=null">
id=#{id} 
</if>
<if test="lastName!=null and lastName!=''">
and last_name like #{lastName} 
</if>
<if test="gender==0 or gender==1">
and gender =#{gender}
</if>
<if test="email!=null and email.trim()!=&quot;&quot;">
and email =#{email}
</if>
</select>

<choose>标签是选择查询
<choose>
<when test="id!=null">
id=#{id}
</when>
<when test="lastName!=null">
last_name like #{lastName}
</when>
<when test="email!=null">
email =#{email}
</when>
<when test="gender!=null">
gender =#{gender}
</when>
<otherwise>gender=1</otherwise>
</choose>

<foreach></foreach>

内置参数 在xml中 _parameter代表参数 _databaseI就是代表当前数据库别名 
bind OGNL绑定到字符串中用在模糊查询
<sql id=“名字”>可抽取sql使用 <include id="名字"> 引用刚才抽取的他的取值是${}
mybatis缓存机制SqlSession 一直开启 与数据库同一次回话查询会放在缓存中,以后需要相同数据直接从缓存拿
失效情况:sqlSession不同 sqlSession相同查询条件不同
二级缓存 一个namespace 对应一个二级缓存
如果回话关闭,一级缓存数据会被保存在2级缓存中,新的回话可以参考2级缓存
内置参数 在xml中 _parameter代表参数 _databaseI就是代表当前数据库别名 
bind OGNL绑定到字符串中用在模糊查询
<sql id=“名字”>可抽取sql使用 <include id="名字"> 引用刚才抽取的他的取值是${}
mybatis缓存机制SqlSession 一直开启 与数据库同一次回话查询会放在缓存中,以后需要相同数据直接从缓存拿
失效情况:sqlSession不同 sqlSession相同查询条件不同
二级缓存 一个namespace 对应一个二级缓存
如果回话关闭,一级缓存数据会被保存在2级缓存中,新的回话可以参考2级缓存






原创粉丝点击