mybatis 入门下

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级缓存






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值