SpringBoot+Mybatis 实现长字符串保存和更新

数据库字段,写成长字符

插入xml,注意两个点,否则会报错

1、长字符串字段不能写if判断:<if test="name != null and name != ">

2、插入的时候做字符串转码:<![CDATA[#{fileCode}]]>

<insert id="insert" parameterType="com.java.core.entity.master.GenTemplateFile" useGeneratedKeys="true"
            keyProperty="id">
        insert into gen_template_file(
        <if test="templateId != null and templateId != ">template_id,</if>
        <if test="name != null and name != ">name,</if>
        file_code,
        <if test="orderNumber != null and orderNumber != 0">order_number,</if>
        <if test="create_by != null and create_by != ">create_by,</if>
        create_time
        )values(
        <if test="templateId != null and templateId != 0">#{templateId},</if>
        <if test="name != null and name != 0">#{name},</if>
        <![CDATA[#{fileCode}]]>,
        <if test="orderNumber != null and orderNumber != ">#{orderNumber},</if>
        <if test="create_by != null and create_by != ">#{create_by},</if>
        sysdate()
        )
    </insert>
经验分享 程序员 微信小程序 职场和发展