<?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.csnf.mapper.CategoryMapper">
  <resultMap id="BaseResultMap" type="com.csnf.entity.Category">
    <id column="category_id" jdbcType="INTEGER" property="category_id" />
    <result column="category_name" jdbcType="VARCHAR" property="category_name" />
    <result column="category_image_src" jdbcType="VARCHAR" property="categoryImageSrc" />
  </resultMap>
  <delete id="deleteByPrimaryKey" parameterType="Integer">
    delete from category
    where category_id = #{category_id,jdbcType=INTEGER}
  </delete>
  <insert id="insert" parameterType="com.csnf.entity.Category">
    <selectKey keyProperty="category_id" order="AFTER" resultType="Integer">
      SELECT LAST_INSERT_ID()
    </selectKey>
    insert into category (category_name, category_image_src)
    values (#{category_name,jdbcType=VARCHAR}, #{categoryImageSrc,jdbcType=VARCHAR})
  </insert>
  <update id="updateByPrimaryKey" parameterType="com.csnf.entity.Category">
    update category
    set category_name = #{category_name,jdbcType=VARCHAR},
      category_image_src = #{categoryImageSrc,jdbcType=VARCHAR}
    where category_id = #{category_id,jdbcType=INTEGER}
  </update>
  <select id="selectByPrimaryKey" parameterType="Integer" resultMap="BaseResultMap">
    select category_id, category_name, category_image_src
    from category
    where category_id = #{category_id,jdbcType=INTEGER}
  </select>
  <select id="selectAll" resultMap="BaseResultMap">
    select category_id, category_name, category_image_src
    from category
  </select>
</mapper>