赞
踩
- @TableName(value = "",autoResultMap = true)
-
- @TableField(typeHandler = FileVoListTypeHandler.class)
-
- public class FileVoListTypeHandler extends ListTypeHandler<FileVo> {
-
- @Override
-
- protected TypeReference<List<FileVo>> specificType() {
-
- return new TypeReference<List<FileVo>>() {
-
- };
-
- }
-
- }
-
-
-
- @MappedJdbcTypes({JdbcType.VARBINARY})
-
- @MappedTypes({List.class})
-
- public abstract class ListTypeHandler<T> extends BaseTypeHandler<List<T>> {
-
- public ListTypeHandler() {
-
- }
-
-
-
- @Override
-
- public void setNonNullParameter(PreparedStatement ps, int i, List<T> parameter, JdbcType jdbcType) throws SQLException {
-
- String content = CollectionUtils.isEmpty(parameter) ? null : JSON.toJSONString(parameter);
-
- ps.setString(i, content);
-
- }
-
- @Override
-
- public List<T> getNullableResult(ResultSet rs, String columnName) throws SQLException {
-
- return this.getListByJsonArrayString(rs.getString(columnName));
-
- }
-
- @Override
-
- public List<T> getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
-
- return this.getListByJsonArrayString(rs.getString(columnIndex));
-
- }
-
- @Override
-
- public List<T> getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
-
- return this.getListByJsonArrayString(cs.getString(columnIndex));
-
- }
-
- private List<T> getListByJsonArrayString(String content) {
-
- return (List)(StringUtils.isEmpty(content) ? new ArrayList() : (List)JSON.parseObject(content, this.specificType(), new Feature[0]));
-
- }
-
- protected abstract TypeReference<List<T>> specificType();
-
- }
如果注解TableName的autoResultMap没有设置,查询时不会映射到字段上
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。