mirror of
https://gitee.com/hhyykk/ipms-sjy.git
synced 2025-07-14 02:55:07 +08:00
增加 MyBatis Plus 的字段加密时,查询的示例
This commit is contained in:
@ -29,29 +29,36 @@ public class EncryptTypeHandler extends BaseTypeHandler<String> {
|
||||
@Override
|
||||
public String getNullableResult(ResultSet rs, String columnName) throws SQLException {
|
||||
String value = rs.getString(columnName);
|
||||
return getResult(value);
|
||||
return decrypt(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
|
||||
String value = rs.getString(columnIndex);
|
||||
return getResult(value);
|
||||
return decrypt(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
|
||||
String value = cs.getString(columnIndex);
|
||||
return getResult(value);
|
||||
return decrypt(value);
|
||||
}
|
||||
|
||||
private String getResult(String value) {
|
||||
private static String decrypt(String value) {
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
return getEncryptor().decrypt(value);
|
||||
}
|
||||
|
||||
private StringEncryptor getEncryptor() {
|
||||
public static String encrypt(String rawValue) {
|
||||
if (rawValue == null) {
|
||||
return null;
|
||||
}
|
||||
return getEncryptor().encrypt(rawValue);
|
||||
}
|
||||
|
||||
private static StringEncryptor getEncryptor() {
|
||||
if (encryptor != null) {
|
||||
return encryptor;
|
||||
}
|
||||
|
Reference in New Issue
Block a user