mybatis的报错总结_____2Error updating database. Cause: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the ri

In the preparation of the dynamic properties of wrong sql trim, as shown below:

Error demonstration:

(Xml configuration file interface in :)

1  <update id="modifyBill" parameterType="Bill">
2         update smbms_bill
3         <trim suffix="set" prefixOverrides="," prefix="where id=#{id}">
4         <if test="billCode!=null">billCode=#{billCode},</if>
5             <if test="productName!=null">productName=#{productName},</if>
6             <if test="productDesc!=null">productDesc=#{productDesc}</if>
7         </trim>
8     </update>

Error log:

Database Updating the Cause Error: java.sql.SQLSyntaxErrorException:. AN by You have have the SQL syntax error in your; The Manual Check the MySQL that Corresponds to your The Server Version for right syntax to use near 'WHERE ID = billCode. 3 =' 33333 ', 


/ / log can be seen in print sql statement is wrong, as follows: 
### SQL: Update smbms_bill the above mentioned id = billCode the WHERE ?, productName = = = ?, productDesc the SET??

 

Correct demonstration:

xml configuration file interface in:

 <!--最后一个没有逗号~~~~~-->
    <update id="modifyBill" parameterType="Bill">
        update smbms_bill
        <trim prefix="set" prefixOverrides="," suffix="where id=#{id}">
        <if test="billCode!=null">billCode=#{billCode},</if>
            <if test="productName!=null">productName=#{productName},</if>
            <if test="productDesc!=null">productDesc=#{productDesc}</if>
        </trim>
    </update>

Print out the sql statement:

[com.xbf.dao.bill.BillMapper.modifyBill]-==>  Preparing: update smbms_bill set billCode=?, productName=?, productDesc=? where id=? 

Summary :( find online map, I feel that is very clear!)

prefix: prefix eg: set

prefixOverrides: prefix replacement eg:,

suffix:后缀 eg:where id=#{ id }

Guess you like

Origin www.cnblogs.com/xbfchder/p/11247715.html