zoukankan      html  css  js  c++  java
  • 调研打标(标签)的实现方式(mybatis转换json的方式)

    • mysql 存json,可行,

      • 建议存储标签格式为jsonArray

      • 最终实现为流过滤,代码实现举例

        • create table ep_test_json
          (
              id    int auto_increment
                  primary key,
              extra json null
          );
          INSERT INTO epower_atreus.ep_test_json (id, extra) VALUES (1, '[1, 2, 3, 4, 5, 6, 7]');
          INSERT INTO epower_atreus.ep_test_json (id, extra) VALUES (3, '[1, 2, 3, 4, 5, 6]');
          INSERT INTO epower_atreus.ep_test_json (id, extra) VALUES (5, '[1, 2, 3, 4, 5]');
          
        • @Data
          @EqualsAndHashCode(callSuper = false)
          @TableName(value = "epower_atreus.ep_test_json", autoResultMap = true)
          public class EpTestJson implements Serializable {
          
              @TableId(value = "id", type = IdType.AUTO)
              private Integer id;
          
              @TableField(typeHandler = FastjsonTypeHandler.class)
              private List<Integer> extra;
          
          
          }
          
        • final List<EpTestJson> list = jsonService.list().stream()
                          .filter(json -> json.getExtra().stream().anyMatch(i -> i == 7))
                          .collect(Collectors.toList());
          
      • 缺点是无法做索引,只能先查出全部数据然后逐一匹配; 且无法做常规分页

    • 关联表,可行,

      • 增加索引,
      • 缺点是会多占用一定的空间,可优化点是,在标签表增加主表的主键,这样仅需标签表设置索引列
    • 位移打标,可行,

      • 比如, 01010101,01000001,每个固定位置的1代表固定的标签,只要约定好位置信息,一个Int就足够存储标签了
      • 缺点是在数据库里对比数据时不方便比对
    三分热血值得你十二分努力。
  • 相关阅读:
    mysql 查询某年某月数据~(如果数据表用时间戳)
    mongo_4.25 find() hasNext() next()
    在YII框架中有2中方法创建对象:
    bootsrap[$data]
    date
    cookie
    JavaScript shell, 可以用到 JS 的特性, forEach
    在 Yii框架中使用session 的笔记:
    mysql查询今天、昨天、7天、近30天、本月、上一月 数据
    Python 自定义异常练习
  • 原文地址:https://www.cnblogs.com/woooodlin/p/tagging_for_something.html
Copyright © 2011-2022 走看看