确认
- [x] 我的版本是最新版本, 我的版本号与 version 相同, 并且项目里无依赖冲突
- [x] 我已经在 issue 中搜索过, 确认问题没有被提出过
- [x] 我已经修改标题, 将标题中的 描述 替换为遇到的问题
功能改进
entity: @TableField(value = "password",typeHandler = EncryptTypeHandler.class) private java.lang.String password;
@TableField(value="mobile",typeHandler = EncryptTypeHandler.class)
private java.lang.String mobile;
,
config:
@Bean
public ConfigurationCustomizer configurationCustomizer(CryptoUtils cryptoUtils) {
return configuration -> {
TypeHandlerRegistry registry = configuration.getTypeHandlerRegistry();
//注册加密TypeHandler
registry.register(new EncryptTypeHandler( cryptoUtils));
}, Service: public TestMybatisEntity testMethod1(TestMybatisEntity entity) { //插入数据 testMybatisMapper.insert(entity); //获取插入的数据 TestMybatisEntity chatEntity2 = testMybatisMapper.selectById(entity.getChatId()); return chatEntity2; }
public TestMybatisEntity testMethod2(TestMybatisEntity entity) {
testMybatisMapper.insertDemo(entity);
TestMybatisEntity chatEntity2 = testMybatisMapper.selectMobile(entity.getChatId());
return chatEntity2;
}
,调试运行,发现使用mybatis的testMethod2,在xml文件中使用resultmap和insertDemo手工指定typeHandler,插入insertDemo和selectMobile都是成功的,能够正确的插入和读取数据,但是使用mybatis-plus的testMethod1,插入数据insert是成功的,调用EncryptTypeHandler,将数据加密后插入数据库,但是通过selectById获取数据是错误的,读取的数据并没有经过EncryptTypeHandler,获取到的数据是数据库的加密数据,也就是说,加密是成功的,解密是失败的,这是什么原因?谢谢
参考资料
No response
Comment From: miemieYaho
git形式给出你的复现demo
Comment From: joeyu2003
src.zip,这是一个删减版本的主要代码,mybatis-plus的加密过程是成功的,但是解密就是失败的,registry.register(/String.class, JdbcType.VARCHAR,/new EncryptTypeHandler( cryptoUtils));如果register带上String.class, JdbcType.VARCHAR,参数,则所有的String都会使用EncryptTypeHandler,而不是缺省使用StringTypeHandler,这样也不符合预期,只有敏感字段才需要加密存储,非敏感信息源数据存储,不知道是不是用法不对,请指教!
Comment From: miemieYaho
把你registry.register部分移出,另外请上传到git我们不要zip