在使用通用mapper插入数据UUID回显
在使用通用mapper插入数据时,发现主键没有回显,我这里的主键是UUID的,解决方案是:配置一个MapperScannerConfigurer.
@Bean MapperScannerConfigurer getMapperScannerConfigurer(){ MapperScannerConfigurer mapperScannerConfigurer = new MapperScannerConfigurer(); mapperScannerConfigurer.setBasePackage("com.yujiangjun.dao.mybatis.mapper"); Properties properties = new Properties(); properties.setProperty("mappers","com.yujiangjun.dao.mybatis.base.BaseMapper"); properties.setProperty("notEmpty", "false"); properties.setProperty("IDENTITY","SELECT REPLACE(UUID(),''-'','''')"); //主键UUID回写方法执行顺序,默认AFTER,可选值为(BEFORE|AFTER) properties.setProperty("ORDER","BEFORE"); mapperScannerConfigurer.setProperties(properties); return mapperScannerConfigurer; }
说明:我使用的通用mapper是tk.mybatis:mapper.所以在这里导入的tk的MapperScannerConfigurer