mybatis 按照 map 动态进行 insert 和 update

 

按照 map 动态 进行 insert 和 update

<!--更新用户数据-->
    <update id="update" parameterType="com.Data">
        update loy_data
        <set>
            <if test="deleteFlg != null">
                DELETE_FLG = #{deleteFlg},
            </if>
            UPDATED_AT = #{updatedAt},
            UPDATED_BY = #{updatedBy}
            <foreach collection="fields" index="key" item="value">
                , ${key} = #{value}
            </foreach>
        </set>
        where id = #{id}
    </update>

    <!--新增用户数据-->
    <insert id="insert" parameterType="com.Data" keyProperty="id" useGeneratedKeys="true">
        insert into loy_data(id, DELETE_FLG, CREATED_AT, CREATED_BY, UPDATED_AT, UPDATED_BY
        <foreach collection="fields.keys" index="index" item="key">
            , ${key}
        </foreach>
        )
        VALUES
        (#{id}, #{deleteFlg}, #{createdAt}, #{createdBy}, #{updatedAt}, #{updatedBy}
        <foreach collection="fields.values" index="index" item="value">
            , #{value}
        </foreach>
        )
    </insert>
/**
 * (LoyData)实体类
 *
 * @author wanghang
 * @since 2020-05-14 17:49:31
 */
@SequenceId(property = "id")
public class LoyData implements Serializable {

    private static final long serialVersionUID = 238203000278523870L;

    /**
     * 数据ID
     */
    private Long id;
    /**
     * 删除标志 1:删除 0:不删除
     */
    private Integer deleteFlg;
    /**
     * 创建时间
     */
    private Long createdAt;
    /**
     * 创建人
     */
    private Long createdBy;
    /**
     * 最近更新时间
     */
    private Long updatedAt;
    /**
     * 最近更新人
     */
    private Long updatedBy;
    /**
     * 动态列
     */
    private Map<String, Object> fields;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Integer getDeleteFlg() {
        return deleteFlg;
    }

    public void setDeleteFlg(Integer deleteFlg) {
        this.deleteFlg = deleteFlg;
    }

    public Long getCreatedAt() {
        return createdAt;
    }

    public void setCreatedAt(Long createdAt) {
        this.createdAt = createdAt;
    }

    public Long getCreatedBy() {
        return createdBy;
    }

    public void setCreatedBy(Long createdBy) {
        this.createdBy = createdBy;
    }

    public Long getUpdatedAt() {
        return updatedAt;
    }

    public void setUpdatedAt(Long updatedAt) {
        this.updatedAt = updatedAt;
    }

    public Long getUpdatedBy() {
        return updatedBy;
    }

    public void setUpdatedBy(Long updatedBy) {
        this.updatedBy = updatedBy;
    }

    public Map<String, Object> getFields() {
        return fields;
    }

    public void setFields(Map<String, Object> fields) {
        this.fields = fields;
    }

    @Override
    public String toString() {
        return "LoyaltyData{" +
                "id=" + id +
                ", deleteFlg=" + deleteFlg +
                ", createdAt=" + createdAt +
                ", createdBy=" + createdBy +
                ", updatedAt=" + updatedAt +
                ", updatedBy=" + updatedBy +
                ", fields=" + fields +
                '}';
    }
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值