GoodsMapper.xml 2.54 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.yoho.ufo.dal.GoodsMapper">
  <resultMap id="BaseResultMap" type="com.yoho.ufo.dal.model.Goods">
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="product_id" jdbcType="INTEGER" property="productId" />
    <result column="color_id" jdbcType="INTEGER" property="colorId" />
    <result column="color_name" jdbcType="VARCHAR" property="colorName" />
    <result column="goods_name" jdbcType="VARCHAR" property="goodsName" />
    <result column="color_image" jdbcType="VARCHAR" property="colorImage" />
    <result column="is_default" jdbcType="CHAR" property="isDefault" />
  </resultMap>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
    delete from goods
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <insert id="insert" parameterType="com.yoho.ufo.dal.model.Goods" useGeneratedKeys="true" keyProperty="id" >
    insert into goods (id, product_id, color_id, 
      color_name, goods_name, color_image, 
      is_default)
    values (#{id,jdbcType=INTEGER}, #{productId,jdbcType=INTEGER}, #{colorId,jdbcType=INTEGER}, 
      #{colorName,jdbcType=VARCHAR}, #{goodsName,jdbcType=VARCHAR}, #{colorImage,jdbcType=VARCHAR}, 
      #{isDefault,jdbcType=CHAR})
  </insert>
  <update id="updateByPrimaryKey" parameterType="com.yoho.ufo.dal.model.Goods">
    update goods
    set product_id = #{productId,jdbcType=INTEGER},
      color_id = #{colorId,jdbcType=INTEGER},
      color_name = #{colorName,jdbcType=VARCHAR},
      goods_name = #{goodsName,jdbcType=VARCHAR},
      color_image = #{colorImage,jdbcType=VARCHAR},
      is_default = #{isDefault,jdbcType=CHAR}
    where id = #{id,jdbcType=INTEGER}
  </update>
  <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    select id, product_id, color_id, color_name, goods_name, color_image, is_default
    from goods
    where id = #{id,jdbcType=INTEGER}
  </select>
  <select id="selectAll" resultMap="BaseResultMap">
    select id, product_id, color_id, color_name, goods_name, color_image, is_default
    from goods
  </select>
  <select id="selectByProductId" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    select id, product_id, color_id, color_name, goods_name, color_image, is_default
    from goods
    where product_id in
   		<foreach item="item" index="index" collection="list" open="(" separator="," close=")">  
	  		#{item}  
	 	</foreach>
  </select>
</mapper>