当前位置:   article > 正文

mybatis plus json查询_mybatis-plus json字段查询

mybatis-plus json字段查询
  1. @TableName(value = "",autoResultMap = true)
  2. @TableField(typeHandler = FileVoListTypeHandler.class)
  3. public class FileVoListTypeHandler extends ListTypeHandler<FileVo> {
  4. @Override
  5. protected TypeReference<List<FileVo>> specificType() {
  6. return new TypeReference<List<FileVo>>() {
  7. };
  8. }
  9. }
  10. @MappedJdbcTypes({JdbcType.VARBINARY})
  11. @MappedTypes({List.class})
  12. public abstract class ListTypeHandler<T> extends BaseTypeHandler<List<T>> {
  13. public ListTypeHandler() {
  14. }
  15. @Override
  16. public void setNonNullParameter(PreparedStatement ps, int i, List<T> parameter, JdbcType jdbcType) throws SQLException {
  17. String content = CollectionUtils.isEmpty(parameter) ? null : JSON.toJSONString(parameter);
  18. ps.setString(i, content);
  19. }
  20. @Override
  21. public List<T> getNullableResult(ResultSet rs, String columnName) throws SQLException {
  22. return this.getListByJsonArrayString(rs.getString(columnName));
  23. }
  24. @Override
  25. public List<T> getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
  26. return this.getListByJsonArrayString(rs.getString(columnIndex));
  27. }
  28. @Override
  29. public List<T> getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
  30. return this.getListByJsonArrayString(cs.getString(columnIndex));
  31. }
  32. private List<T> getListByJsonArrayString(String content) {
  33. return (List)(StringUtils.isEmpty(content) ? new ArrayList() : (List)JSON.parseObject(content, this.specificType(), new Feature[0]));
  34. }
  35. protected abstract TypeReference<List<T>> specificType();
  36. }

如果注解TableName的autoResultMap没有设置,查询时不会映射到字段上

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/笔触狂放9/article/detail/988951
推荐阅读
相关标签
  

闽ICP备14008679号