mybatis动态新增sql语句

青春壹個敷衍的年華 提交于 2019-12-27 16:39:52

注意传入的参数是实体类型
<!--动态新增-->
<insert id="insertGeo" parameterType="com.entity.GovernmentDetail">
    insert into GOVERNMENT_DETAIL
    <trim prefix="(" suffix=")" suffixOverrides=",">
        <if test="unitType != null">UNIT_TYPE,</if>
        <if test="plateCode != null">PLAT_CODE,</if>
        <if test="descrip != null">DESCRIP,</if>
        <if test="businessGuid != null">BUSINESS_GUID,</if>
        <if test="hotLine != null">HOT_LINE,</if>
        <if test="lineAdress != null">LINE_ADRESS,</if>
        <if test="extend1 != null">EXTEND1,</if>
        <if test="extend2 != null">EXTEND2,</if>
        CREATE_TIME,
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
        <if test="unitType != null">#{unitType,jdbcType=VARCHAR},</if>
        <if test="plateCode != null">#{plateCode,jdbcType=VARCHAR},</if>
        <if test="descrip != null">#{descrip,jdbcType=VARCHAR},</if>
        <if test="businessGuid != null">#{businessGuid,jdbcType=VARCHAR},</if>
        <if test="hotLine != null">#{hotLine,jdbcType=VARCHAR},</if>
        <if test="lineAdress != null">#{lineAdress,jdbcType=VARCHAR},</if>
        <if test="extend1 != null">#{extend1,jdbcType=VARCHAR},</if>
        <if test="extend2 != null">#{extend2,jdbcType=VARCHAR},</if>
        NOW(),
    </trim>
</insert>

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!