修复 错误
This commit is contained in:
+1
-1
@@ -42,7 +42,7 @@ import java.util.Map;
|
||||
@MapperScans({
|
||||
@MapperScan(basePackages ={"co.yixiang.**.service.mapper", "co.yixiang.config"},sqlSessionFactoryRef = "shangcheng"),
|
||||
@MapperScan(basePackages = {"com.zsw.erp.datasource.mappers"},sqlSessionFactoryRef = "erp"),
|
||||
@MapperScan(value = "${yudao.info.base-package}", annotationClass = Mapper.class,
|
||||
@MapperScan(basePackages = {"${yudao.info.base-package}", "cn.iocoder.yudao"}, annotationClass = Mapper.class,
|
||||
lazyInitialization = "${mybatis.lazy-initialization:false}") // Mapper 懒加载,目前仅用于单元测试
|
||||
})
|
||||
@Configuration
|
||||
|
||||
+68
@@ -0,0 +1,68 @@
|
||||
package cn.iocoder.yudao.framework.mybatis.core.handler;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.type.CollectionType;
|
||||
import org.apache.ibatis.type.BaseTypeHandler;
|
||||
import org.apache.ibatis.type.JdbcType;
|
||||
import org.apache.ibatis.type.MappedJdbcTypes;
|
||||
import org.apache.ibatis.type.MappedTypes;
|
||||
|
||||
|
||||
import java.sql.CallableStatement;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* zyj
|
||||
*/
|
||||
@MappedJdbcTypes(JdbcType.VARCHAR) // 数据库中该字段存储的类型
|
||||
@MappedTypes(List.class) // 需要转换的对象
|
||||
public class ListIntToListLongTypeHandler extends BaseTypeHandler<List<Long>> {
|
||||
|
||||
private static ObjectMapper mObjectMapper = new ObjectMapper();
|
||||
|
||||
@Override
|
||||
public void setNonNullParameter(PreparedStatement preparedStatement, int i, List<Long> longs, JdbcType jdbcType) throws SQLException {
|
||||
String json = JSONUtil.toJsonStr(longs);
|
||||
preparedStatement.setObject(i, json);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Long> getNullableResult(ResultSet resultSet, String columnName) throws SQLException {
|
||||
String value = resultSet.getString(columnName);
|
||||
return getLongs(value);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<Long> getNullableResult(ResultSet resultSet, int i) throws SQLException {
|
||||
String value = resultSet.getString(i);
|
||||
return getLongs(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Long> getNullableResult(CallableStatement callableStatement, int i) throws SQLException {
|
||||
String value = callableStatement.getString(i);
|
||||
return getLongs(value);
|
||||
}
|
||||
|
||||
private List<Long> getLongs(String value) {
|
||||
if (ObjectUtil.isNotEmpty(value)) {
|
||||
try {
|
||||
CollectionType type = mObjectMapper.getTypeFactory().constructCollectionType(ArrayList.class, Long.class);
|
||||
List<Long> longs = mObjectMapper.readValue(value , type);
|
||||
return longs;
|
||||
} catch (JsonProcessingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user