<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.alibaba.uyuni.dal.mapper.StudentDoMapperExt" >
<select id="getPageList" parameterType="int" resultType="com.alibaba.uyuni.biz.common.bo.dto.StudentDto">
select id ,name,age,sex,grade,class as team,teacher from student where is_deleted='n' order by id limit #{offset},8
</select>
<select id="getTotoalNum" resultType="int" >
select count(*) from student where is_deleted='n'
</select >
<select id="condtionQuery" parameterType="com.alibaba.uyuni.biz.common.bo.dto.StudentDto" resultType="com.alibaba.uyuni.biz.common.bo.dto.StudentDto">
select id ,name,age,sex,grade,class as team,teacher from student
<where>
<include refid="query_student_where"/>
</where>
</select>
<sql id="query_student_where">
<if test='name != null and name != ""'>
and name like '%${name}%'
</if>
<if test='age != null and age != ""'>
and age = #{age}
</if>
<if test='sex != null and sex != ""'>
and sex = #{sex}
</if>
<if test=' grade != null and grade != ""'>
and grade = #{grade}
</if>
<if test=' team != null and team != ""'>
and class = #{team}
</if>
<if test=' teacher != null and teacher != ""'>
and teacher = #{teacher}
</if>
and is_deleted='n'
</sql>
</mapper>
使用了<where>标签就不需要加where关键字,<where>标签会自动去掉第一个条件的and,or
本文出自 “点滴积累” 博客,请务必保留此出处http://tianxingzhe.blog.51cto.com/3390077/1736937