今天在使用Mybatis时出现错误:
### Error updating database. Cause: java.sql.SQLException: MYSQL:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'CHECKNOTPASSREASON='驾驶证未满一年以上;其他原因:qwe'
where OID' at line 3
### The error may involve com.zte.ums.ztev.database.dao.drivermgt.DriverMgtDao.modifyDriver-Inline
### The error occurred while setting parameters
### SQL: update BUS_DRIVER SET CHECKTHROUGH=? CHECKNOTPASSREASON=? where OID = ?
### Cause: java.sql.SQLException: MYSQL:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'CHECKNOTPASSREASON='驾驶证未满一年以上;其他原因:qwe'
where OID' at line 3
检查发现是因为:
<if test="driverLicenseScan !=null">DRIVERLICENSESCAN=#{driverLicenseScan},</if>
<if test="address !=null">ADDRESS=#{address},</if>
<if test="checkThrough !=null">CHECKTHROUGH=#{checkThrough}</if>
<if test="checkNotPassReason !=null">CHECKNOTPASSREASON=#{checkNotPassReason}</if>
<if test="userGrade !=null">USERGRADE=#{userGrade}</if>
中“ #{checkThrough}”,“ #{userGrade}”和“ #{checkNotPassReason}”后面缺少逗号“,”
改为:
<if test="driverLicenseScan !=null">DRIVERLICENSESCAN=#{driverLicenseScan},</if>
<if test="address !=null">ADDRESS=#{address},</if>
<if test="checkThrough !=null">CHECKTHROUGH=#{checkThrough},</if>
<if test="checkNotPassReason !=null">CHECKNOTPASSREASON=#{checkNotPassReason},</if>
<if test="userGrade !=null">USERGRADE=#{userGrade},</if>
就好了!