MyBatis-Plus 逻辑删除
话不多说,直入主题,在使用 MP的的时候切记 不要使用数据库的一些关键字,我的数据库是MYSQL,当然别的数据库暂时还没遇到,
@Data
@AllArgsConstructor
@NoArgsConstructor
public class User {
@TableId(type = IdType.AUTO)
private Long id;
private String name;
private int age;
private String email;
@TableField(fill = FieldFill.INSERT)
private Date create_time;
@TableField(fill = FieldFill.INSERT_UPDATE)
private Date update_time;
@Version//乐观锁注解
private Integer version;
@TableLogic //逻辑删除 这里不能使用 delete关键字,不然会报SQl 语句错误
private Integer delete;
}
报错
org.springframework.jdbc.BadSqlGrammarException:
### Error querying 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 'delete FROM user
WHERE delete=0) TOTAL' at line 1
### The error may exist in com/andy/mybatisplus/mapper/UserMapper.java (best guess)
### The error may involve defaultParameterMap
### The error occurred while setting parameters
### SQL: SELECT COUNT(*) FROM (SELECT id,name,age,email,create_time,update_time,version,delete FROM user WHERE delete=0) TOTAL
### 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 'delete FROM user
WHERE delete=0) TOTAL' at line 1
; 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 'delete FROM user
WHERE delete=0) TOTAL' at line 1