mybatis 使用标签时<if>标签注意事项
2017-09-14 18:16
519 查看
1.dao层代码
public int getCount(@Param("sex")String sex, @Param("name")String name);
2..xml代码 ,错误的写法,看似正确的等于号
第一种 因为参数类型是字符串,必须这样写,否则等于号判断无效!
select count(*)
from PRO_PROJECT t
where 1=1
<if test="sex == '1'.toString()">
and name=#{name}
</if>
第二种 这种方法与参数类型为整形时一样
public int getCount(@Param("sex")String sex, @Param("name")String name);
2..xml代码 ,错误的写法,看似正确的等于号
select count(*) from PRO_PROJECT t where 1=1 <if test="sex == '1'"> and name=#{name} </if>正确的写法有两种
第一种 因为参数类型是字符串,必须这样写,否则等于号判断无效!
select count(*)
from PRO_PROJECT t
where 1=1
<if test="sex == '1'.toString()">
and name=#{name}
</if>
第二种 这种方法与参数类型为整形时一样
select count(*) from PRO_PROJECT t where 1=1 <if test="sex == 1"> and name=#{name} </if>
相关文章推荐
- mybatis映射文件中<if>使用注意事项
- 使用 <pre> 标签样式的注意事项
- mybaits where 语句中使用<if></if>注意事项
- 开发日志:使用struts2标签[<s:if><s:property>等]获取boolean属性需注意
- jsp页面,使用Struts2标签,传递和获取Action类里的参数,注意事项。<s:a action><s:iterator><s:param>ognl表达式 在编写SSH2项目的时候,除
- Mybatis的mapper.xml的传值和<if></if>标签的使用(学习分享)
- struts1标签-<html:radio> 使用注意事项
- mybatis <![CDATA[ ]]>的作用、使用、注意事项。
- 在使用struts标签时,把<s:if>中的test写成了text
- 02-Struts2-struts2 <s:if>标签以及 #,%{},%{#}的使用方法
- 前端的一些注意事项 <img onerror="src='images/no.png'">标签引起的异常
- thinkphp模板中标签<volist>,<if>和 U函数的使用
- struts2中<s:if>标签的使用
- [JQuery]关于使用jsp:include标签及<%@ include标签时要注意的事项
- 核心标签库<c:set>标签、<c:choose>标签、<c:forEach>标签&<c:if>标签的使用例子
- SoapUI使用注意事项——在<!CDATA>节点之前不要有空格
- <c:if>标签使用
- mybatis <forEach>标签的使用
- mybatis <where>、<set>、<trim>、<sql>、<foreach>标签的使用
- MyBatis中<resultMap>的<association>和<collection>标签的使用