|
@@ -0,0 +1,34 @@
|
|
|
+package org.jeecg.modules.system.util;
|
|
|
+import org.apache.ibatis.type.BaseTypeHandler;
|
|
|
+import org.apache.ibatis.type.JdbcType;
|
|
|
+import org.jeecg.modules.system.util.AES;
|
|
|
+import java.sql.CallableStatement;
|
|
|
+import java.sql.PreparedStatement;
|
|
|
+import java.sql.ResultSet;
|
|
|
+import java.sql.SQLException;
|
|
|
+/**
|
|
|
+ * @author starmark
|
|
|
+ * @date 19-12-17 下午8:38
|
|
|
+ */
|
|
|
+public class AESEncryptHandler extends BaseTypeHandler {
|
|
|
+ @Override
|
|
|
+ public void setNonNullParameter(PreparedStatement ps, int i, Object parameter, JdbcType jdbcType) throws SQLException {
|
|
|
+ ps.setString(i, AES.encrypt((String)parameter));
|
|
|
+ }
|
|
|
+ @Override
|
|
|
+ public String getNullableResult(ResultSet rs, String columnName) throws SQLException {
|
|
|
+ String columnValue = rs.getString(columnName);
|
|
|
+ return AES.decrypt(columnValue);
|
|
|
+ }
|
|
|
+ @Override
|
|
|
+ public String getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
|
|
|
+ String columnValue = rs.getString(columnIndex);
|
|
|
+ return AES.decrypt(columnValue);
|
|
|
+ }
|
|
|
+ @Override
|
|
|
+ public String getNullableResult(CallableStatement cs, int columnIndex)
|
|
|
+ throws SQLException {
|
|
|
+ String columnValue = cs.getString(columnIndex);
|
|
|
+ return AES.decrypt(columnValue);
|
|
|
+ }
|
|
|
+}
|