通用的sql语句,常用:wher条件、查询列。
<!-- 用户查询条件定义为sql片断
建议对单表的查询条件单独抽取sql片段,提高公用性
注意:不要将where标签放在sql片断
-->
<sqlid="query_user_where">
<!-- test中userCustom.username表示从userQueryVo读取属性值 -->
<iftest="userCustom!=null">
<iftest="userCustom.username!=nulland userCustom.username!=''">
and username like '%${userCustom.username}%'
</if>
<iftest="userCustom.sex!=nulland userCustom.sex!=''">
and sex = #{userCustom.sex}
</if>
</if>
</sql>
<selectid="findUserCount"parameterType="cn.itcast.mybatis.po.UserQueryVo"resultType="int">
select count(*) from user
<!-- where标签相当于where关键字,可以自动去除第一个and -->
<where>
<!-- 引用sql片断,如果sql片断和引用不在同一个mapper必须前边加namespace -->
<includerefid="query_user_where"></include>
</where>
</select>新闻热点
疑难解答