NoticeMapper.xml 5.82 KB
<?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.yohobuy.platform.dal.cms.INoticeDao" >
  <resultMap id="BaseResultMap" type="com.yohobuy.platform.dal.cms.model.Notice" >
    <id column="id" property="id" jdbcType="INTEGER" />
    <result column="title" property="title" jdbcType="VARCHAR" />
    <result column="img" property="img" jdbcType="VARCHAR" />
    <result column="url" property="url" jdbcType="VARCHAR" />
    <result column="position" property="position" jdbcType="TINYINT" />
    <result column="show_channels" property="showChannels" jdbcType="VARCHAR" />
    <result column="create_time" property="createTime" jdbcType="INTEGER" />
    <result column="status" property="status" jdbcType="TINYINT" />
    <result column="start_time" property="startTime" jdbcType="INTEGER" />
    <result column="end_time" property="endTime" jdbcType="INTEGER" />
  </resultMap>
  <sql id="Base_Column_List" >
    id, title, img, url, position, show_channels, create_time, status, start_time, end_time
  </sql>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
    select 
    <include refid="Base_Column_List" />
    from notice
    where id = #{id,jdbcType=INTEGER}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
    delete from notice
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <insert id="insert" parameterType="com.yohobuy.platform.dal.cms.model.Notice" useGeneratedKeys="true" keyProperty="id" >
    insert into notice (id, title, img, url, position, create_time,  status, start_time, end_time, show_channels)
    values (#{id,jdbcType=INTEGER}, #{title,jdbcType=VARCHAR}, #{img,jdbcType=VARCHAR},
      #{url,jdbcType=VARCHAR}, #{position,jdbcType=TINYINT}, UNIX_TIMESTAMP(),
      #{status,jdbcType=TINYINT}, #{startTime,jdbcType=INTEGER},
      #{endTime,jdbcType=INTEGER}, #{showChannels,jdbcType=VARCHAR}
      )
  </insert>
  <insert id="insertSelective" parameterType="com.yohobuy.platform.dal.cms.model.Notice" useGeneratedKeys="true" keyProperty="id" >
    insert into notice
    <trim prefix="(" suffix=")" suffixOverrides="," >
      id,
      <if test="title != null" >
        title,
      </if>
      <if test="img != null" >
        img,
      </if>
      <if test="url != null" >
        url,
      </if>
      <if test="position != null" >
        position,
      </if>
        create_time,
      <if test="status != null" >
        status,
      </if>
      <if test="startTime != null" >
        start_time,
      </if>
      <if test="endTime != null" >
        end_time,
      </if>
      <if test="showChannels != null" >
        show_channels,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      #{id,jdbcType=INTEGER},
      <if test="title != null" >
        #{title,jdbcType=VARCHAR},
      </if>
      <if test="img != null" >
        #{img,jdbcType=VARCHAR},
      </if>
      <if test="url != null" >
        #{url,jdbcType=VARCHAR},
      </if>
      <if test="position != null" >
        #{position,jdbcType=TINYINT},
      </if>
      UNIX_TIMESTAMP(),
      <if test="status != null" >
        #{status,jdbcType=TINYINT},
      </if>
      <if test="startTime != null" >
        #{startTime,jdbcType=INTEGER},
      </if>
      <if test="endTime != null" >
        #{endTime,jdbcType=INTEGER},
      </if>
      <if test="showChannels != null" >
        #{showChannels,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.yohobuy.platform.dal.cms.model.Notice" >
    update notice
    <set >
      <if test="title != null" >
        title = #{title,jdbcType=VARCHAR},
      </if>
      <if test="img != null" >
        img = #{img,jdbcType=VARCHAR},
      </if>
      <if test="url != null" >
        url = #{url,jdbcType=VARCHAR},
      </if>
      <if test="position != null" >
        position = #{position,jdbcType=TINYINT},
      </if>
      <if test="status != null" >
        status = #{status,jdbcType=TINYINT},
      </if>
      <if test="showChannels != null" >
        show_channels = #{showChannels,jdbcType=VARCHAR},
      </if>
      <if test="startTime != null" >
        start_time = #{startTime,jdbcType=INTEGER},
      </if>
      <if test="endTime != null" >
        end_time = #{endTime,jdbcType=INTEGER},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.yohobuy.platform.dal.cms.model.Notice" >
    update notice
    set title = #{title,jdbcType=VARCHAR},
      img = #{img,jdbcType=VARCHAR},
      url = #{url,jdbcType=VARCHAR},
      position = #{position,jdbcType=TINYINT},
      show_channels = #{showChannels,jdbcType=VARCHAR},
      status = #{status,jdbcType=TINYINT},
      start_time = #{startTime,jdbcType=INTEGER},
      end_time = #{endTime,jdbcType=INTEGER}
    where id = #{id,jdbcType=INTEGER}
  </update>

  <sql id="page_condition">
    <trim prefix="where" prefixOverrides="and | or">
      <if test="notice.title != null" >
        and title like CONCAT('%',#{notice.title},'%')
      </if>
      <if test="notice.showChannels != null">
        and ( show_channels like CONCAT('%',#{notice.showChannels},'%') or ISNULL(show_channels) or not LENGTH(show_channels) )
      </if>
      <if test="notice.position != null" >
        and position = #{notice.position}
      </if>
    </trim>
  </sql>

  <select id="selectSelective"  resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from notice
   <include refid="page_condition"/>
    order by id DESC
    limit #{start}, #{size}
  </select>

  <select id="selectCountSelective" resultType="java.lang.Integer">
    select
    count(*)
    from notice
    <include refid="page_condition"/>
  </select>

</mapper>