PostgreSQL与MyBatisPlus逻辑删除的深度兼容实践
1. 问题现象与初步分析
当我们在SpringBoot项目中整合PostgreSQL与MyBatisPlus时,一个典型的错误场景如下:
// 实体类定义
@Data
public class User {
@TableLogic
private Boolean deleted = false;
}
// 查询操作
userMapper.selectCount(new QueryWrapper<User>().eq("username", "test"));
执行时抛出异常:
ERROR: operator does not exist: boolean = integer
Hint: No operator matches the given name and argument types. You might need to add explicit type casts.
核心矛盾点在于:
- PostgreSQL是严格的类型系统,不允许布尔值与数值直接比较
- MyBatisPlus默认将逻辑删除值转换为0/1的数值形式
2. 类型系统差异的本质
2.1 PostgreSQL的严格类型检查
PostgreSQL作为学院派数据库代表,其类型系统具有以下特点:
| 特性 | PostgreSQL | MySQL |
|---|---|---|
| 布尔类型 | 原生支持 | 用TINYINT模拟 |
| 隐式类型转换 | 禁止 |


被折叠的 条评论
为什么被折叠?



