在项目过程中,我使用@TableLogic规定逻辑删除后,在使用updateById时 被标记@TableLogic的字段总是出现在SQL语句的WHERE条件后面,并且始终是一个常量(这里是1),如下是源码和测试的log输出,目前还不明白到底怎么回事~ 已经排错一天了。。。
// Entity层
*/
@TableLogic
private Integer isShow;
/**
* 检索首字母
*/
private String firstLetter;
/**
* 排序
*/
private Integer sort;
// Controller层
/**
* 修改
*/
@RequestMapping("/update")
// @RequiresPermissions("commodity:brand:update")
public R update(@RequestBody BrandEntity brand){
brandService.updateById(brand);
return R.ok();
}
// application.yml
mybatis-plus:
mapper-locations: classpath:/mapper/**/*.xml
# 主键自增
global-config:
db-config:
id-type: auto
# 逻辑删除
logic-delete-value: 0 #已删除
logic-not-delete-value: 1 #未删除
// pom.xml
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.2.0</version>
</dependency>
// 启动类
@SpringBootApplication
public class HsplivingCommodityApplication {
public static void main(String[] args) {
ConfigurableApplicationContext ioc = SpringApplication.run(HsplivingCommodityApplication.class, args);
System.out.println(ioc);
}
}
// 测试log输出
### 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 'WHERE id=1 AND is_show=1' at line 1
### The error may exist in com/leon/commodity/dao/BrandDao.java (best guess)
### The error may involve com.leon.commodity.dao.BrandDao.updateById-Inline
### The error occurred while setting parameters
### SQL: UPDATE commodity_brand WHERE id=? AND is_show=1
### Cause: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax;
// 数据库
CREATE TABLE `commodity_brand` (
id BIGINT NOT NULL AUTO_INCREMENT COMMENT 'id', `name` CHAR(50) COMMENT '品牌名',
logo VARCHAR(1200) COMMENT 'logo',
description LONGTEXT COMMENT '说明',
is_show TINYINT COMMENT '显示',
first_letter CHAR(1) COMMENT '检索首字母',
sort INT COMMENT '排序',
PRIMARY KEY (id)
)CHARSET=utf8mb4 COMMENT='家居品牌';
跪求基友们指点~~