插⼊(Insert)SQL可动态设置字段属性如图:合理运⽤动态sql,也可随意控制插⼊字段信息,代码中只对appVersion和userMobile赋值,
<insert id="insertDataPointInfo" keyColumn="id" keyProperty="id" useGeneratedKeys="true">
INSERT INTO data_point_info
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">
id,
</if>
<if test="itemId != null">
item_id,
</if>
<if test="distinctId != null">
distinct_id,
</if>
<if test="userId != null">
user_id,
</if>
<if test="username != null">
user_name,
</if>insert语句字段顺序
<if test="userMobile != null">
user_mobile,
</if>
<if test="os != null">
os,
</if>
<if test="osVersion != null">
os_version,
</if>
<if test="appVersion != null">
app_version,
</if>
<if test="ip!= null">
ip,
</if>
<if test="opTime!= null">
op_time,
</if>
</trim>
VALUES
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">
#{id,jdbcType=INTEGER},
</if>
<if test="itemId != null">
#{itemId,jdbcType=INTEGER},
</if>
<if test="distinctId != null">
#{distinctId,jdbcType=VARCHAR},
#{distinctId,jdbcType=VARCHAR}, </if>
<if test="userId != null">
#{userId,jdbcType=VARCHAR},
</if>
<if test="username != null">
#{username,jdbcType=VARCHAR}, </if>
<if test="userMobile != null">
#{userMobile,jdbcType=VARCHAR}, </if>
<if test="os != null">
#{os,jdbcType=VARCHAR},
</if>
<if test="osVersion != null">
#{osVersion,jdbcType=VARCHAR}, </if>
<if test="appVersion != null">
#{appVersion,jdbcType=VARCHAR}, </if>
<if test="ip != null">
#{ip,jdbcType=VARCHAR},
</if>
<if test="opTime != null">
#{opTime},
</if>
</trim>
</insert>

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。