mybatis-crypto
mybatis-crypto copied to clipboard
请问下加密拦截器不挂在 “ParameterHandler”上是有什么考量吗
没什么特殊考量,感觉挂在 ParameterHandler 也可以
好的,谢谢大佬。
另外想要请教一下 MybatisQueryEncryptionPlugin 这个类是做什么用的呢。 阅读了一下源码没能理解
MybatisQueryEncryptionPlugin 是用来支持加密查询 这个 issue: https://github.com/WhiteDG/mybatis-crypto/issues/1
懂了,谢谢。
没考虑到这个场景,因为我们这边的需求是加密字段还需要支持模糊搜索
我在想keepParameter的实现用属性拷贝的方式会不会性能好点
懂了,谢谢。
没考虑到这个场景,因为我们这边的需求是加密字段还需要支持模糊搜索
加密字段模糊搜索可能比较难实现,这里实现的只是简单的 equals 查询
我在想keepParameter的实现用属性拷贝的方式会不会性能好点
能具体说一下吗,现在的实现是加密执行完 sql 之后再对原来的参数执行一次解密
我在想keepParameter的实现用属性拷贝的方式会不会性能好点
能具体说一下吗,现在的实现是加密执行完 sql 之后再对原来的参数执行一次解密
就是一个不成熟的小想法。 加密执行前把parameter参数深拷贝缓存下,执行后再把拷贝的值赋值给原来的参数
一开始是这样实现的,不过我对深拷贝不是很懂,所以就用了 kryo 实现,后面感觉多引一个库也不是太好,就干脆直接解密,从头到尾操作同一个实例。
大佬您好,还有个问题想要请教一下您。 在下面这段代码中,不是已经拿到了 paramName了吗,为什么还需要对String特殊处理呢
private static void addParamToEncrypt(Map<String, EncryptedParamConfig> shouldEncryptParams, int paramIndex, Class<?> parameterType, String paramName, EncryptedField encryptedField) {
EncryptedParamConfig encryptedParamConfig;
if (encryptedField != null) {
encryptedParamConfig = new EncryptedParamConfig(paramName, encryptedField);
} else {
encryptedParamConfig = new EncryptedParamConfig(paramName, null, IEncryptor.class);
}
shouldEncryptParams.put(paramName, encryptedParamConfig);
if (parameterType.equals(String.class)) {
EncryptedParamConfig encryptedParamConfig0;
String paramIndexKey = "param" + (paramIndex + 1);
if (encryptedField != null) {
encryptedParamConfig0 = new EncryptedParamConfig(paramIndexKey, encryptedField);
} else {
encryptedParamConfig0 = new EncryptedParamConfig(paramIndexKey, null, IEncryptor.class);
}
shouldEncryptParams.put(paramIndexKey, encryptedParamConfig0);
}
}
作用是处理 mybatis 自动往 parameterMap 中添加的 param1/param2... 这些顺序映射参数。
比如这个 mapper 接口:
List<User> selectByName(@EncryptedField(encryptor = MyEncryptor.class) @Param("name") String name);
在 xml 中写 sql 的时候,可以用 #{name} 也可以用 #{param1}
<select id="selectByName" resultType="io.github.whitedg.demo.entity.User">
select *
from t_user
where name = #{name}
</select>
<select id="selectByName" resultType="io.github.whitedg.demo.entity.User">
select *
from t_user
where name = #{param1}
</select>