老师,请问下,通用mapper怎么设置不更新和不插入空字符串?

来源:8-19 规则持久化02-推模式

靈靇

2020-12-15

老师,请问下,通用mapper怎么设置不更新和不插入空字符串?
这边通过insertSelective和UpdateByPrimaryKeySelectiveMapper发现前端传过来的空字符会更新和插入,应该null和空字符都不插入才对吧

写回答

1回答

大目

2020-12-16

您好,直接判断下就OK了。

if(入参不是null) {

insertSelective / UpdateByPrimaryKey

}

通用mapper不会管你是不是想要插入的是空还是不是空。

0
1
靈靇
可以通过在配置文件开启是否判断为空字符串或null则不执行 mapper: mapper: - tk.mybatis.mapper.common.Mapper notEmpty: true notEmpty insertSelective 和 updateByPrimaryKeySelective 中,是否判断字符串类型 !=''。 配置方式: mapper.not-empty=true
2020-12-29
共1条回复

Spring Cloud Alibaba微服务从入门到进阶

面向未来微服务:熟练掌握Spring Cloud Alibaba

3085 学习 · 1324 问题

查看课程