|
@@ -0,0 +1,54 @@
|
|
|
+package com.chelvc.framework.database.interceptor;
|
|
|
+
|
|
|
+import java.sql.CallableStatement;
|
|
|
+import java.sql.PreparedStatement;
|
|
|
+import java.sql.ResultSet;
|
|
|
+import java.sql.SQLException;
|
|
|
+import java.sql.Types;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+import com.chelvc.framework.base.context.JacksonContextHolder;
|
|
|
+import com.chelvc.framework.base.model.File;
|
|
|
+import com.fasterxml.jackson.core.type.TypeReference;
|
|
|
+import org.apache.ibatis.type.BaseTypeHandler;
|
|
|
+import org.apache.ibatis.type.JdbcType;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 文件信息列表字段类型处理实现
|
|
|
+ *
|
|
|
+ * @author Woody
|
|
|
+ * @date 2023/7/17
|
|
|
+ */
|
|
|
+public class FilesTypeHandler extends BaseTypeHandler<List<File>> {
|
|
|
+ /**
|
|
|
+ * 类型引用实例
|
|
|
+ */
|
|
|
+ private static final TypeReference<List<File>> REFERENCE = new TypeReference<List<File>>() {
|
|
|
+ };
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void setNonNullParameter(PreparedStatement ps, int i, List<File> parameter, JdbcType jdbcType)
|
|
|
+ throws SQLException {
|
|
|
+ if (CollectionUtils.isEmpty(parameter)) {
|
|
|
+ ps.setNull(i, Types.VARCHAR);
|
|
|
+ } else {
|
|
|
+ ps.setString(i, JacksonContextHolder.serialize(parameter));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<File> getNullableResult(ResultSet rs, String columnName) throws SQLException {
|
|
|
+ return JacksonContextHolder.deserialize(rs.getString(columnName), REFERENCE);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<File> getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
|
|
|
+ return JacksonContextHolder.deserialize(rs.getString(columnIndex), REFERENCE);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<File> getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
|
|
|
+ return JacksonContextHolder.deserialize(cs.getString(columnIndex), REFERENCE);
|
|
|
+ }
|
|
|
+}
|