Results 3 comments of wangjp

感谢你抽空帮忙解答; 开始通过上面java配置的方式配置了通用mapper,并设置属性properties.setProperty("notEmpty", "true"); 打断点可以看到进入了tk.mybatis.mapper.entity.Config.class中 this.notEmpty = Boolean.valueOf(properties.getProperty("notEmpty"));读取到的值是true, 但接着进入tk.mybatis.mapper.provider.base.BaseSelectProvider.class中的 sql.append(SqlHelper.whereAllIfColumns(entityClass, isNotEmpty()));;读取的isNotEmpty()一直是false, 所以导致(为空的参数也加入了查询条件,按照配置说明,应该会加上xxx!=null,这个notEmpty同样作用updateByPrimaryKeySelective) DEBUG druid.sql.Statement 134 -| {conn-110004, pstmt-120004} created. SELECT count(0) FROM base_supplier WHERE state = ? AND code = ?...

然后我今天下午,把上面java配置方式的通用mapper注释掉了, /*Properties properties = new Properties(); properties.setProperty("mappers", CoreMapper.class.getName()); properties.setProperty("notEmpty", "true"); properties.setProperty("IDENTITY", "MYSQL"); properties.setProperty("ORDER","AFTER"); mapperScannerConfigurer.setProperties(properties);*/ 并且在application.properties属性文件中加入: # 通用 Mapper 配置 mapper.mappers=com.kszn.tms.datasource.mybatis.CoreMapper mapper.not-empty=true mapper.identity=MYSQL, 之后就正常啦,sql.append(SqlHelper.whereAllIfColumns(entityClass, isNotEmpty()));;读取的isNotEmpty()返回true了, 不会再出现空的属性值也参与查询条件了,updateByPrimaryKeySelective也正常了,

原先我在项目中没有加入Atomikos分布式事务,通用mapper使用的就是javabean配置方式notEmpty为true是没问题的; 加入了Atomikos分布式事务之后,通用mapper使用javabean配置方式("notEmpty", "true")就无效了,必须使用属性配置:mapper.not-empty=true才可以, 我开始尝试打断点看tk.mybatis.mapper.entity.Config.class中this.notEmpty被赋值的地方,只有两处: 一个是通过:public void setNotEmpty(boolean notEmpty) { this.notEmpty = notEmpty; },属性配置方式进入这里; 另外一个是通过:this.notEmpty = Boolean.valueOf(properties.getProperty("notEmpty"));javabean配置方式进入这里。