首页 > 其他分享 >SSM -Other

SSM -Other

时间:2023-04-12 22:06:02浏览次数:31  
标签:菜单 return List categoryEntity SSM entities Other getSort

启动排除包

//排除包
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})

数据库不存在字段

//  表示当前属性不是数据库的字段,但在项目中必须使用 不存在
   @TableField(exist=false)
   private List<CategoryEntity> children;
   或者
   private transient List<CategoryEntity> children;

物理删除 逻辑删除

mybatis-plus:
  global-config:
      logic-delete-value: 1 #逻辑已经删除(默认1)
      logic-not-delete-value: 0 #逻辑未经删除(默认0
/** 恰恰相反 自定义处理 value="1",delval = "0"
 * 是否显示[0-不显示,1显示]
 */
@TableLogic(value="1",delval = "0")
private Integer showStatus;      

日志级别

logging:
  level:
    com.atguigu.gulimall: debug # 包名: debug
public void updateSpuAttr(Long spuId, List<ProductAttrValueEntity> entities) {
    //更新 把之删除 不知道是否是更新还是新增是否  还是是否存在
    this.baseMapper.delete(new QueryWrapper<ProductAttrValueEntity>().eq("spu_id",spuId));
    //在进行更新(就是插入数据) 遍历entities
    List<ProductAttrValueEntity> collect = entities.stream().map(item -> {
        item.setSpuId(spuId);
        return item;
    }).collect(Collectors.toList());
    this.saveBatch(collect);
}

stream 流使用

// 获取菜单的子菜单
 @Override
    public List<CategoryEntity> listWithTree() {
//        1.查出所有分类 2.组装表
        List<CategoryEntity> entities = baseMapper.selectList(null);
//        3.找出一级分类 父分类id getParentCid是0
//        Java8 使用 stream().filter()过滤List对象(查找符合条件的对象集合) 箭头函数 返回categoryEntity中的getParentCid是==0的
        List<CategoryEntity> level1Menus = entities.stream().filter(categoryEntity -> {
            return categoryEntity.getParentCid() == 0;
//            collect 收集成一个集合collect(Collectors.toList()
        }).map((menu)->{
//            setChildren 调用getChildrens 从菜单中的子菜单获取菜单,将找到的menu设置进入,还要传入entities
            menu.setChildren(getChildrens(menu,entities));
            return menu;
//            找到还要排序  传入menu1,menu2 他们中有getSort
        }).sorted((menu1,menu2)->{
            return (menu1.getSort() == null?0:menu1.getSort()) - (menu2.getSort() == null?0:menu2.getSort());
        }).collect(Collectors.toList());
        return level1Menus;
    }

//    子菜单 递归 找到菜单的子菜单
    /**
     *定义getChildrens 方法 传入CategoryEntity root 和从哪里获取子菜单? 从 List<CategoryEntity> all【上一个方法中】获取
     */
    private List<CategoryEntity> getChildrens(CategoryEntity root, List<CategoryEntity> all){
//        也是通过 过滤
        List<CategoryEntity> chilidren = all.stream().filter(categoryEntity -> {
//            如果ategoryEntity.getParentCid() 父i == 子菜单id
            return categoryEntity.getParentCid().equals(root.getCatId());
        }).map(categoryEntity -> {
             
//            找到子菜单的菜单 递归找子菜单,如果子菜单有菜单 继续寻找菜单
            categoryEntity.setChildren(getChildrens(categoryEntity, all));
            return categoryEntity;
        }).sorted((menu1, menu2) -> {
//            找到之后在排序
            return (menu1.getSort() == null?0:menu1.getSort()) - (menu2.getSort() == null?0:menu2.getSort());
        }).collect(Collectors.toList());
        return chilidren;
    }

标签:菜单,return,List,categoryEntity,SSM,entities,Other,getSort
From: https://blog.51cto.com/u_15993308/6186313

相关文章