分页sql

<?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="ssm.mapper.StudentMapper" >
  <resultMap id="BaseResultMap" type="ssm.pojo.Student" >
    <id column="id" property="id" jdbcType="INTEGER" />
    <result column="name" property="name" jdbcType="VARCHAR" />
    <result column="birthday" property="birthday" jdbcType="DATE" />
    <result column="cid" property="cid" jdbcType="INTEGER" />
    <result column="favorite" property="favorite" jdbcType="VARCHAR" />
    <result column="picture" property="picture" jdbcType="VARCHAR" />
  </resultMap>
  <sql id="Base_Column_List" >
    id, name, birthday, cid, favorite, picture
  </sql>
  
  <!-- 带分页的列表 -->
    <select id="selectPaging"    parameterType="ssm.pojo.PageInfo"   resultMap="BaseResultMap">
  select  *  from  student
  <where>  
  <if test="keyWord.firstCondition != null and keyWord.firstCondition != '' " >
  name  like   "%${keyWord.firstCondition}%"
</if>
<if test="keyWord.secondCondition   != null and keyWord.secondCondition != '' " >
  and favorite= #{keyWord.secondCondition} 
</if>
<if test="keyWord.thirdCondition   != null and  keyWord.thirdCondition  != '' " >
  and cid= #{keyWord.thirdCondition} 
</if>
<if test="keyWord.fourthCondition  != null and keyWord.fourthCondition != '' " >
  and name= #{keyWord.fourthCondition} 
</if>  

  </where> 
  limit      #{pageRow},#{pageSize} 
  </select>
  <!-- 获取数据总数 -->
    <select id="getSum"    resultType="java.lang.Integer"    parameterType="ssm.pojo.PageInfo">
  select  count(*)  from   student
  <where>  
   <if test="keyWord.firstCondition != null and keyWord.firstCondition != '' " >
  name  like   "%${keyWord.firstCondition}%"
</if>
<if test="keyWord.secondCondition   != null and keyWord.secondCondition != '' " >
  and favorite= #{keyWord.secondCondition} 
</if> 
<if test="keyWord.thirdCondition   != null and  keyWord.thirdCondition  != '' " >
  and cid= #{keyWord.thirdCondition} 
  </if>

<if test="keyWord.fourthCondition  != null and keyWord.fourthCondition != '' " >
  and name= #{keyWord.fourthCondition}  
</if> 
  </where>
  </select>
  
  
  
  
  
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
    select 
    <include refid="Base_Column_List" />
    from student
    where id = #{id,jdbcType=INTEGER}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
    delete from student
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <insert id="insert" parameterType="ssm.pojo.Student" >
    insert into student (id, name, birthday, 
      cid, favorite, picture
      )
    values (#{id,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, #{birthday,jdbcType=DATE}, 
      #{cid,jdbcType=INTEGER}, #{favorite,jdbcType=VARCHAR}, #{picture,jdbcType=VARCHAR}
      )
  </insert>
  
  
  
  
  <insert id="insertSelective" parameterType="ssm.pojo.Student" >
    insert into student
    <trim prefix="(" suffix=")" suffixOverrides="," >
  <!--     <if test="id != null" >
        id,
      </if> -->
      id,
      <if test="name != null" >
        name,
      </if>
      <if test="birthday != null" >
        birthday,
      </if>
      <if test="cid != null" >
        cid,
      </if>
      <if test="favorite != null" >
        favorite,
      </if>
      <if test="picture != null" >
        picture,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
<!--     <if test="id != null" >
        #{id,jdbcType=INTEGER},
      </if>  -->
null,
      <if test="name != null" >
        #{name,jdbcType=VARCHAR},
      </if>
      <if test="birthday != null" >
        #{birthday,jdbcType=DATE},
      </if>
      <if test="cid != null" >
        #{cid,jdbcType=INTEGER},
      </if>
      <if test="favorite != null" >
        #{favorite,jdbcType=VARCHAR},
      </if>
      <if test="picture != null" >
        #{picture,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
  
  
  
  <update id="updateByPrimaryKeySelective" parameterType="ssm.pojo.Student" >
    update student
    <set >
      <if test="name != null" >
        name = #{name,jdbcType=VARCHAR},
      </if>
      <if test="birthday != null" >
        birthday = #{birthday,jdbcType=DATE},
      </if>
      <if test="cid != null" >
        cid = #{cid,jdbcType=INTEGER},
      </if>
      <if test="favorite != null" >
        favorite = #{favorite,jdbcType=VARCHAR},
      </if>
      <if test="picture != null" >
        picture = #{picture,jdbcType=VARCHAR},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="ssm.pojo.Student" >
    update student
    set name = #{name,jdbcType=VARCHAR},
      birthday = #{birthday,jdbcType=DATE},
      cid = #{cid,jdbcType=INTEGER},
      favorite = #{favorite,jdbcType=VARCHAR},
      picture = #{picture,jdbcType=VARCHAR}
    where id = #{id,jdbcType=INTEGER}
  </update>
</mapper>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值