mybatis 新增方法

<insert id="insertDept" parameterType="com.ruoyi.project.platform.district.domain.District">
        insert into fb_district
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null and id != 0">id,</if>
            <if test="parentId != null and parentId != 0">parent_id,</if>
            <if test="ancestors != null and ancestors != '' ">ancestors,</if>
            <if test="districtName != null and districtName != '' ">district_name,</if>
            <if test="districtNickName != null and districtNickName != '' ">district_nick_name,</if>
            <if test="districtType != null and districtType != '' ">district_type,</if>
            <if test="districtLeader != null and districtLeader != '' ">district_leader,</if>
            <if test="districtLeaderId != null and districtLeaderId != 0 ">district_leader_id,</if>
            <if test="phoneNumber != null and phoneNumber != '' ">phone_number,</if>
            <if test="phoneOffice != null and phoneOffice != '' ">phone_office,</if>
            <if test="email != null and email != '' ">email,</if>
            <if test="orderNum != null and orderNum != '' ">order_num,</if>
            <if test="districtAddress != null and districtAddress != '' ">district_address,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null and id != 0">#{id},</if>
            <if test="parentId != null and parentId != 0">#{parentId},</if>
            <if test="ancestors != null and ancestors != '' ">#{ancestors},</if>
            <if test="districtName != null and districtName != '' ">#{districtName},</if>
            <if test="districtNickName != null and districtNickName != '' ">#{districtNickName},</if>
            <if test="districtType != null and districtType != '' ">#{districtType},</if>
            <if test="districtLeader != null and districtLeader != '' ">#{districtLeader},</if>
            <if test="districtLeaderId != null and districtLeaderId != 0 ">#{districtLeaderId},</if>
            <if test="phoneNumber != null and phoneNumber != '' ">#{phoneNumber},</if>
            <if test="phoneOffice != null and phoneOffice != '' ">#{phoneOffice},</if>
            <if test="email != null and email != '' ">#{email},</if>
            <if test="orderNum != null and orderNum != '' ">#{orderNum},</if>
            <if test="districtAddress != null and districtAddress != '' "> #{districtAddress},</if>
        </trim>
    </insert>

之前没加trim 老是报错,加上之后就可以了

猜你喜欢

转载自blog.csdn.net/qq_29072049/article/details/88732185