<?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="org.example.mybatisplus.mapper.ProductMapper">

    <resultMap id="BaseResultMap" type="org.example.mybatisplus.concrete.Product">
            <id property="id" column="id" jdbcType="INTEGER"/>
            <result property="name" column="name" jdbcType="VARCHAR"/>
            <result property="price" column="price" jdbcType="INTEGER"/>
            <result property="version" column="version" jdbcType="INTEGER"/>
    </resultMap>

    <sql id="Base_Column_List">
        id,name,price,
        version
    </sql>
    <insert id="insertSelective">
        insert into t_product
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="name != null">name,</if>
            <if test="price != null">price,</if>
            <if test="version != null">version,</if>
        </trim>
        values
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id,jdbcType=INTEGER},</if>
            <if test="name != null">#{name,jdbcType=VARCHAR},</if>
            <if test="price != null">#{price,jdbcType=INTEGER},</if>
            <if test="version != null">#{version,jdbcType=INTEGER},</if>
        </trim>
    </insert>
    <delete id="deleteByIdAndName">
        delete
        from t_product
        where id = #{id,jdbcType=NUMERIC}
          AND name = #{name,jdbcType=VARCHAR}
    </delete>
    <update id="updateName">
        update t_product
        set name = #{name,jdbcType=VARCHAR}
    </update>
    <select id="selectAllByName" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from t_product
        where
        name = #{name,jdbcType=VARCHAR}
    </select>
</mapper>
