当前使用版本(必填,否则不予处理)

com.baomidou mybatis-plus-boot-starter 3.5.3.1

该问题是如何引起的?(确定最新版也有问题再提!!!)

之前是重写了updateById,引入乐观锁以后在po对应字段里用了@TableField(exist=false),然后使用了BaseMapper的updateById,执行后version=?前面出现了\n,导致报错

重现步骤(如果有就写完整)

PO: @TableField(exist = false) private ChatUser from;

@TableField(exist = false)
private ChatUser to;

@TableId(value = "chatId", type = IdType.AUTO)
private Long chatId;

@TableField("fromUsername")
private String fromUsername;

@TableField("toUsername")
private String toUsername;

@TableField("content")
private String content;

@TableField("time")
private LocalDateTime time;

@TableField("read")
private Boolean read;

@Version
@TableField("version")
private Integer version;

......

DAO: 使用了BaseMapper自带的updateById

Service层调用了该方法 final List chats = chatMapper.selectUnread(receiver, sender); chats.forEach(chat -> { chat.setRead(true); chatMapper.updateById(chat); }); 然后报错 测试用updateBatchById也报错

报错信息

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 'read=1,\nversion=2 WHERE chatId=8 AND version=1' at line 5\r\n### The error may exist in com/yhm/universityhelper/dao/ChatMapper.java (best guess)\r\n### The error may involve com.yhm.universityhelper.dao.ChatMapper.updateById-Inline\r\n### The error occurred while setting parameters\r\n### SQL: UPDATE uh_chat SET fromUsername=?, toUsername=?, content=?, time=?, read=?, version=? WHERE chatId=? AND version=?\r\n### 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 'read=1,\nversion=2 WHERE chatId=8 AND version=1' at line 5\n; bad SQL grammar []; nested exception is 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 'read=1,\nversion=2 WHERE chatId=8 AND version=1' at line 5"

Comment From: qmdx

\n 哪里来的?

Comment From: zhangfangzhou01

已解决,字段改成isRead后正常