数据库url:jdbc:mysql://localhost:3306/test_lib_dev?serverTimezone=Asia/Shanghai
mybatis xml批量更新配置:
String[] adminAccounts = new String[] {"20204058631b264"};
Integer delTAdminInfo = mapper.delTAdminInfo(adminAccounts);
Integer delTAdminInfo(String[] list);
Integer delTAdminInfo = mapper.delTAdminInfo("20204058631b264");
Integer delTAdminInfo(String... list);
<update id="updTAdminInfos" parameterType="java.util.List">
<foreach collection="list" item="item" index="index" open="" close="" separator=";">
update t_admin_info
<set>
<if test="item.adminName != null and item.adminName != ''">
admin_name = #{item.adminName,jdbcType=VARCHAR},
</if>
<if test="item.pwd != null and item.pwd != ''">
pwd = #{item.pwd,jdbcType=VARCHAR},
</if>
<if test="item.gender != null and item.gender != ''">
gender = #{item.gender,jdbcType=VARCHAR},
</if>
<if test="item.age != null">
age = #{item.age,jdbcType=INTEGER},
</if>
<if test="item.idNum != null and item.idNum != ''">
id_num = #{item.idNum,jdbcType=VARCHAR},
</if>
<if test="item.telNum != null and item.telNum != ''">
tel_num = #{item.telNum,jdbcType=VARCHAR},
</if>
<if test="item.mobilePhone != null and item.mobilePhone != ''">
mobile_phone = #{item.mobilePhone,jdbcType=VARCHAR},
</if>
<if test="item.email != null and item.email != ''">
email = #{item.email,jdbcType=VARCHAR},
</if>
<if test="item.image != null and item.image != ''">
image = #{item.image,jdbcType=VARCHAR},
</if>
<if test="item.birthDate != null and item.birthDate != ''">
birth_date = #{item.birthDate,jdbcType=DATE},
</if>
<if test="item.address != null and item.address != ''">
address = #{item.address,jdbcType=DATE},
</if>
<if test="item.roleId != null">
role_id = #{item.roleId,jdbcType=INTEGER},
</if>
<if test="item.libraryCode != null and item.libraryCode != ''">
library_code = #{item.libraryCode,jdbcType=VARCHAR},
</if>
<if test="item.libraryName != null and item.libraryName != ''">
library_name = #{item.libraryName,jdbcType=VARCHAR},
</if>
<if test="item.status != null">
status = #{item.status,jdbcType=TINYINT},
</if>
<if test="item.hobby != null and item.hobby != ''">
hobby = #{item.hobby,jdbcType=VARCHAR},
</if>
<if test="item.updatedBy != null and item.updatedBy != ''">
updated_by = #{item.updatedBy,jdbcType=VARCHAR},
</if>
updated_dt = now(),
</set>
where
admin_account = #{item.adminAccount,jdbcType=VARCHAR}
</foreach>
</update>
### 提示如下错误:
org.apache.ibatis.logging.jdbc.BaseJdbcLogger DEBUG ==> Preparing: update t_admin_info SET admin_name = ?, updated_dt = now() where admin_account = ? ; update t_admin_info SET admin_name = ?, updated_dt = now() where admin_account = ?
org.apache.ibatis.logging.jdbc.BaseJdbcLogger DEBUG ==> Parameters: 开发3(String), 20204058631b263(String), 开发4(String), 20204058631b264(String)
Exception in thread "main" org.apache.ibatis.exceptions.PersistenceException:
### Error 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 right syntax to use near 'update t_admin_info
SET admin_name = '开发4',
' at line 24
修改数据库url:
数据库url:jdbc:mysql://localhost:3306/test_lib_dev?allowMultiQueries=true&serverTimezone=Asia/Shanghai
又提示:
Exception in thread "main" org.apache.ibatis.exceptions.PersistenceException:
### Error building SqlSession.
### Cause: org.apache.ibatis.builder.BuilderException: Error creating document instance. Cause: org.xml.sax.SAXParseException; lineNumber: 17; columnNumber: 114; 对实体 "serverTimezone" 的引用必须以 ';' 分隔符结尾。
at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:80)
at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:64)
at com.zj.test.TestUpdate.main(TestUpdate.java:25)
最后将数据库url:jdbc:mysql://localhost:3306/test_lib_dev?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&zeroDateTimeBehavior=convertToNull&serverTimezone=Asia/Shanghai
问题解决,记录一哈!