<?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.dao.CapitalMapper">
  <resultMap id="BaseResultMap" type="com.entity.Capital">
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="name" jdbcType="VARCHAR" property="name" />
    <result column="img" jdbcType="VARCHAR" property="img" />
    <result column="price" jdbcType="INTEGER" property="price" />
  </resultMap>
  <resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="com.entity.Capital">
    <result column="note" jdbcType="LONGVARCHAR" property="note" />
  </resultMap>
  <sql id="Base_Column_List">
    id, `name`, img, price
  </sql>
  <sql id="Blob_Column_List">
    note
  </sql>
  <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="ResultMapWithBLOBs">
    select
    <include refid="Base_Column_List" />
    ,
    <include refid="Blob_Column_List" />
    from capital
    where id = #{id,jdbcType=INTEGER}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
    delete from capital
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <insert id="insert" parameterType="com.entity.Capital">
    insert into capital ( id, `name`, img, price, note)
    values (
    #{id,jdbcType=INTEGER},
    #{name,jdbcType=VARCHAR},
    #{img,jdbcType=VARCHAR},
    #{price,jdbcType=INTEGER},
    #{note,jdbcType=LONGVARCHAR}
      )
  </insert>
  <insert id="insertSelective" parameterType="com.entity.Capital">
    insert into capital
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        id,
      </if>
      <if test="name != null">
        `name`,
      </if>
      <if test="img != null">
        img,
      </if>
      <if test="price != null">
        price,
      </if>
      <if test="note != null">
        note,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="id != null">
        #{id,jdbcType=INTEGER},
      </if>
      <if test="name != null">
        #{name,jdbcType=VARCHAR},
      </if>
      <if test="img != null">
        #{img,jdbcType=VARCHAR},
      </if>
      <if test="price != null">
        #{price,jdbcType=INTEGER},
      </if>
      <if test="note != null">
        #{note,jdbcType=LONGVARCHAR},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.entity.Capital">
    update capital
    <set>
      <if test="name != null">
        `name` = #{name,jdbcType=VARCHAR},
      </if>
      <if test="img != null">
        img = #{img,jdbcType=VARCHAR},
      </if>
      <if test="price != null">
        price = #{price,jdbcType=INTEGER},
      </if>
      <if test="note != null">
        note = #{note,jdbcType=LONGVARCHAR},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKeyWithBLOBs" parameterType="com.entity.Capital">
    update capital
    set img = #{img,jdbcType=VARCHAR},
      `name` = #{name,jdbcType=VARCHAR},
      price = #{price,jdbcType=VARCHAR},
      note = #{note,jdbcType=LONGVARCHAR}
    where id = #{id,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.entity.Capital">
    update capital
    set img = #{img,jdbcType=VARCHAR},
      `name` = #{name,jdbcType=VARCHAR},
      price = #{price,jdbcType=INTEGER}
    where id = #{id,jdbcType=INTEGER}
  </update>


  <select id="getCount" parameterType="java.util.Map" resultType="int">
    select count(*) from capital where 1=1
    <if test="name != null">
      and name like concat('%',#{name,jdbcType=VARCHAR},'%')
    </if>
  </select>
  <select id="getAll" parameterType="java.util.Map" resultMap="ResultMapWithBLOBs">
    select
    <include refid="Base_Column_List" />
    from capital where 1=1
    <if test="name != null">
      and name like concat('%',#{name,jdbcType=VARCHAR},'%')
    </if>
    order by id desc
  </select>
  <select id="getByPage" parameterType="java.util.Map" resultMap="ResultMapWithBLOBs">
    select
    <include refid="Base_Column_List" />
    from capital where 1=1
    <if test="name != null">
      and name like concat('%',#{name,jdbcType=VARCHAR},'%')
    </if>
    order by id desc
    <if test="pageno!=null and pageSize!=null">
      limit #{pageno},#{pageSize}
    </if>
  </select>


</mapper>
