mybatis @param注解

碰到一个单条插入操作,但是,需要从外面传入一个String类型的参数,和一个对象实体的参数

int insertIntoTable(@Param("tableNamePostfix") String tableNamePostfix, @Param("data") WeeinOaoStatisticsInfoDO statisticsInfoDO);

这里就是指定了实体为data
然后在xml中取出data里面的各个值

<insert id="insertIntoTable" parameterType="com.weein.oao.shop.base.entity.WeeinOaoStatisticsInfoDO">
        insert into T_WEEIN_OAO_STATISTICS_INFO_${tableNamePostfix}
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="data.id != null">
                id,
            </if>
            <if test="data.minipId != null">
                minip_id,
            </if>
            <if test="data.openId != null">
                open_id,
            </if>
            <if test="data.type != null">
                `type`,
            </if>
            <if test="data.skuId != null">
                sku_id,
            </if>
            <if test="data.skuName != null">
                sku_name,
            </if>
            <if test="data.productType != null">
                product_type,
            </if>
            <if test="data.provinceCode != null">
                province_code,
            </if>
            <if test="data.provinceName != null">
                province_name,
            </if>
            <if test="data.cityCode != null">
                city_code,
            </if>
            <if test="data.cityName != null">
                city_name,
            </if>
            <if test="data.districtCode != null">
                district_code,
            </if>
            <if test="data.districtName != null">
                district_name,
            </if>
            <if test="data.ext1 != null">
                ext1,
            </if>
            <if test="data.ext2 != null">
                ext2,
            </if>
            <if test="data.ext3 != null">
                ext3,
            </if>
            <if test="data.createTime != null">
                create_time,
            </if>
            <if test="data.updateTime != null">
                update_time,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="data.id != null">
                #{data.id,jdbcType=BIGINT},
            </if>
            <if test="data.minipId != null">
                #{data.minipId,jdbcType=VARCHAR},
            </if>
            <if test="data.openId != null">
                #{data.openId,jdbcType=VARCHAR},
            </if>
            <if test="data.type != null">
                #{data.type,jdbcType=INTEGER},
            </if>
            <if test="data.skuId != null">
                #{data.skuId,jdbcType=VARCHAR},
            </if>
            <if test="data.skuName != null">
                #{data.skuName,jdbcType=VARCHAR},
            </if>
            <if test="data.productType != null">
                #{data.productType,jdbcType=VARCHAR},
            </if>
            <if test="data.provinceCode != null">
                #{data.provinceCode,jdbcType=VARCHAR},
            </if>
            <if test="data.provinceName != null">
                #{data.provinceName,jdbcType=VARCHAR},
            </if>
            <if test="data.cityCode != null">
                #{data.cityCode,jdbcType=VARCHAR},
            </if>
            <if test="data.cityName != null">
                #{data.cityName,jdbcType=VARCHAR},
            </if>
            <if test="data.districtCode != null">
                #{data.districtCode,jdbcType=VARCHAR},
            </if>
            <if test="data.districtName != null">
                #{data.districtName,jdbcType=VARCHAR},
            </if>
            <if test="data.ext1 != null">
                #{data.ext1,jdbcType=VARCHAR},
            </if>
            <if test="data.ext2 != null">
                #{data.ext2,jdbcType=VARCHAR},
            </if>
            <if test="data.ext3 != null">
                #{data.ext3,jdbcType=VARCHAR},
            </if>
            <if test="data.createTime != null">
                #{data.createTime,jdbcType=TIMESTAMP},
            </if>
            <if test="data.updateTime != null">
                #{data.updateTime,jdbcType=TIMESTAMP},
            </if>
        </trim>
    </insert>

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容