Springboot中配置動態sql查詢出現的錯誤syntax error, expect ‘)‘

勇敢的小刀發表於2020-10-08

在springboot中利用mybatis實現動態查詢出現了錯誤

syntax error, expect ')'

原始碼

    <insert id="insertEmploy" parameterType="com.example.springboot06mybatis.bean.Employee">
        insert into employee
        <trim prefix="(" suffixOverrides="," suffix=")">
            <if test="emp_lastName != null">
                lastName,
            </if>
            <if test="email != null">
                email,
            </if>
            <if test="gender != null">
                gender,
            </if>
            <if test="dId != null">
                d_id,
            </if>
        </trim>
        <trim prefix="values=(" suffixOverrides="," suffix=")">
            <if test="emp_lastName != null">
                #{emp_lastName},
            </if>
            <if test="email != null">
                #{email},
            </if>
            <if test="gender != null">
                #{gender},
            </if>
            <if test="dId != null">
                #{dId},
            </if>
        </trim>
    </insert>

之所以會出現錯誤,是因為下面這行語句寫出了"values=("

 <trim prefix="values=(" suffixOverrides="," suffix=")">

只需要將上面修改為如下便可

<trim prefix="values(" suffixOverrides="," suffix=")">

相關文章