<?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.kmall.admin.dao.SpecificationDao">

	<!-- 可根据自己的需求，是否要使用 -->
    <resultMap type="com.kmall.admin.entity.SpecificationEntity" id="specificationMap">
        <result property="id" column="id"/>
        <result property="name" column="name"/>
        <result property="sortOrder" column="sort_order"/>
    </resultMap>

	<select id="queryObject" resultType="com.kmall.admin.entity.SpecificationEntity">
		select * from mall_specification where id = #{value}
	</select>

	<select id="queryList" resultType="com.kmall.admin.entity.SpecificationEntity">
		select * from mall_specification a
		WHERE 1=1
		<if test="ids != null">
			and a.id in
			<foreach item="item" collection="ids" open="(" separator="," close=")">
				#{item}
			</foreach>
		</if>
        <choose>
            <when test="sidx != null and sidx.trim() != ''">
                order by ${sidx} ${order}
            </when>
			<otherwise>
                order by id desc
			</otherwise>
        </choose>
		<if test="offset != null and limit != null">
			limit #{offset}, #{limit}
		</if>
	</select>
	
 	<select id="queryTotal" resultType="int">
		select count(*) from mall_specification
	</select>
	 
	<insert id="save" parameterType="com.kmall.admin.entity.SpecificationEntity" useGeneratedKeys="true" keyProperty="id">
		insert into mall_specification
		(
			`name`, 
			`sort_order`
		)
		values
		(
			#{name}, 
			#{sortOrder}
		)
	</insert>
	 
	<update id="update" parameterType="com.kmall.admin.entity.SpecificationEntity">
		update mall_specification
		<set>
			<if test="name != null">`name` = #{name}, </if>
			<if test="sortOrder != null">`sort_order` = #{sortOrder}</if>
		</set>
		where id = #{id}
	</update>
	
	<delete id="delete">
		delete from mall_specification where id = #{value}
	</delete>
	
	<delete id="deleteBatch">
		delete from mall_specification where id in
		<foreach item="id" collection="array" open="(" separator="," close=")">
			#{id}
		</foreach>
	</delete>

</mapper>