<?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.example.mapper.ProductypeMapper">

    <sql id="Base_Column_List">
        id,product_name
    </sql>

    <select id="selectAll" resultType="com.example.entity.Productype">
        select
        <include refid="Base_Column_List" />
        from product_type
        <where>
            <if test="id != null"> and id = #{id}</if>
            <if test="productName != null"> and product_name like concat('%', #{productName}, '%')</if>
        </where>
        order by id desc
    </select>

    <select id="selectById" resultType="com.example.entity.Productype">
        select
        <include refid="Base_Column_List" />
        from product_type
        where id = #{id}
    </select>

    <delete id="deleteById">
        delete from product_type
        where  id = #{id}
    </delete>

    <insert id="insert" parameterType="com.example.entity.Productype" useGeneratedKeys="true">
        insert into product_type
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="productName != null">product_name,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="productName != null">#{productName},</if>
        </trim>
    </insert>

    <update id="updateById" parameterType="com.example.entity.Productype">
        update product_type
        <set>
            <if test="productName != null">
                product_name = #{productName},
            </if>
        </set>
        where id = #{id} 
    </update>

</mapper>