当前位置: 首页 > news >正文

最优的郑州网站建设外贸流程图片

最优的郑州网站建设,外贸流程图片,两学一做微网站交流,wordpress匿名投稿目录 项目场景:三类分类部分不显示问题描述:数据库序号128后的目录不显示原因分析: 数据库&JAVA后端代码:后端接口 解决方案:1 数据库序号问题2 JAVA层面1 递归改成非递归写法2重新写接口: 查询cat_id为…

目录

  • 项目场景:三类分类部分不显示
  • 问题描述:数据库序号128后的目录不显示
  • 原因分析: 数据库&JAVA后端
    • 代码:
      • 后端接口
  • 解决方案:
    • 1 数据库序号问题
    • 2 JAVA层面
      • 1 递归改成非递归写法
      • 2重新写接口: 查询cat_id为128的子目录
  • 解决方法:加上(long)向下转型自动拆箱
  • 总结: 递归使用要慎重,自动装箱的隐藏机制需要熟悉

项目场景:三类分类部分不显示

实现ElementUI中三级分类的功能,发现没有前端三级目录的二级目录可以新建三级目录,数据库中也有数据,但是无法在前端显示!后端的接口没有返回数据库的数据。
在这里插入图片描述


问题描述:数据库序号128后的目录不显示

提示:这里描述项目中遇到的问题:

例如:数据传输过程中数据不时出现丢失的情况,偶尔会丢失一部分数据
APP 中接收数据代码:

@Overridepublic void run() {bytes = mmInStream.read(buffer);mHandler.obtainMessage(READ_DATA, bytes, -1, buffer).sendToTarget();}

原因分析: 数据库&JAVA后端

提示:例如:在骑行运动耳机目录之后新建的目录,前端界面显示新建成功,数据库也有数据,但是不会显示在前端。

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
数据库中新建数据成功,但是在骑行运动中不会显示出这个新建的婴儿车三级目录。
在这里插入图片描述
IDEA 日志打印记录显示插入成功
在这里插入图片描述
使用sql查询 parent_cid为128的二级目录
在这里插入图片描述

再使用接口测试前端界面没有婴儿车
在这里插入图片描述

代码:

后端接口

//controller层/*** 查出所有分类以及子分类,以树形结构组装起来*/@RequestMapping("/list/tree")public R list(){List<CategoryEntity> entities = categoryService.listWithTree();return R.ok().put("data", entities);}//接口Service层List<CategoryEntity> listWithTree();

Service的具体实现

    @Overridepublic List<CategoryEntity> listWithTree() {//1、查出所有分类List<CategoryEntity> entities = baseMapper.selectList(null);//2、 组装成父子的树形结构//2.1) 找到所有一级分类(父分类id为0)List<CategoryEntity> level1Menus = entities.stream().filter(categoryEntity ->categoryEntity.getCatLevel() == 1).map((menu)->{
//            System.out.println(menu);menu.setChildren(getChildrens(menu,entities));
//            menu.setChildren(getSubtreeById(menu.getCatId(), entities));return menu;}).sorted((menu1,menu2)->{return (menu1.getSort()==null?0:menu1.getSort()) - (menu2.getSort()==null?0:menu2.getSort());}).collect(Collectors.toList());return level1Menus;}//递归查找所有菜单的子菜单private List<CategoryEntity> getChildrens(CategoryEntity root,List<CategoryEntity> all){//1.找到当前菜单的子菜单(每个子菜单还有子菜单)
//        Stream<CategoryEntity> categoryEntityStream = all.stream().filter(entity -> (long)entity.getParentCid() == (long)root.getCatId()); //出bug语句Stream<CategoryEntity> categoryEntityStream = all.stream().filter(entity -> entity.getParentCid() == root.getCatId());Stream<CategoryEntity> mapEntityStream = categoryEntityStream.map(item -> {item.setChildren(getChildrens(item,all));return item;});List<CategoryEntity> children = mapEntityStream.sorted((menu1,menu2)->{return (menu1.getSort()==null?0:menu1.getSort()) - (menu2.getSort()==null?0:menu2.getSort());}).collect(Collectors.toList());return  children;

解决方案:

提示:CatID为128以后的二级目录都不显示数据库中有的三级目录

1 数据库序号问题

DROP TABLE IF EXISTS `pms_category`;CREATE TABLE `pms_category` (`cat_id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '分类id',`name` char(50) DEFAULT NULL COMMENT '分类名称',`parent_cid` bigint(20) DEFAULT NULL COMMENT '父分类id',`cat_level` int(11) DEFAULT NULL COMMENT '层级',`show_status` tinyint(4) DEFAULT NULL COMMENT '是否显示[0-不显示,1显示]',`sort` int(11) DEFAULT NULL COMMENT '排序',`icon` char(255) DEFAULT NULL COMMENT '图标地址',`product_unit` char(50) DEFAULT NULL COMMENT '计量单位',`product_count` int(11) DEFAULT NULL COMMENT '商品数量',PRIMARY KEY (`cat_id`)
) ENGINE=InnoDB AUTO_INCREMENT=1424 DEFAULT CHARSET=utf8mb4 COMMENT='商品三级分类';

AUTO_INCREMENT=1424 原来的数据库是1434,改成了1424让cat_id自增 序号不断层,问题还是解决。 开始以为是数据库很多序号乱码,后面才发现是128二级目录开始出问题。

2 JAVA层面

1 递归改成非递归写法

        //原版代码
//        List<CategoryEntity> children = all.stream().filter(categoryEntity -> {
//            return categoryEntity.getParentCid() == root.getCatId();
//        }).map(categoryEntity->{
//            //2.利用映射递归查找 子菜单的子菜单
//            categoryEntity.setChildren(getChildrens(categoryEntity,all));
//            return categoryEntity;
//        }).sorted((menu1,menu2)->{
//            //3.对当前菜单进行排序,升序排序
//            return (menu1.getSort()==null?0:menu1.getSort()) - (menu2.getSort()==null?0:menu2.getSort());
//        }).collect(Collectors.toList());
//
//        return children;//非递归写法
//        List<CategoryEntity> result = new ArrayList<>();
//        for (int i = 0; i < all.size(); i++){
//            CategoryEntity entity = all.get(i);
//            if (entity.getParentCid() == root.getCatId()) {
//                result.add(entity);
//            }
//        }
//        System.out.println(result);
//
//        for (int i = 0; i < result.size(); i++){
//            CategoryEntity current = result.get(i);
//            List<CategoryEntity> sub = new ArrayList<>();
//            for (int j = 0; j < all.size(); j++){
//                CategoryEntity entity = all.get(j);
//                if (entity.getParentCid() == current.getCatId()) {
//                    List<CategoryEntity> subsub = new ArrayList<>();
//                    for (int k = 0; k < all.size(); k++){
//                        CategoryEntity subEntity = all.get(k);
//                        if (subEntity.getParentCid() == entity.getCatId()){
//                            subsub.add(subEntity);
//                        }
//                    }
//                    entity.setChildren(subsub);
//                    sub.add(entity);
//                }
//            }
//            current.setChildren(sub);
//        }
//
//        return result;

还是不行

2重新写接口: 查询cat_id为128的子目录

//Controller层/*** 信息*/@RequestMapping("/info/{catId}")//@RequiresPermissions("product:category:info")public R info(@PathVariable("catId") Long catId) {CategoryEntity category = categoryService.getById(catId);return R.ok().put("data", category);}//Service层List<CategoryEntity> getSubtreeById(long catId);

接口实现功能

    @Overridepublic List<CategoryEntity> getSubtreeById(long catId) {List<CategoryEntity> entities = baseMapper.selectList(null);List<CategoryEntity> filterList = entities.stream().filter(item -> item.getParentCid() == catId).map(item -> {item.setChildren(getSubtreeById(item.getCatId()));return item;}).collect(Collectors.toList());return filterList;}

前端端口测试: 直接通过id的方式能够查询到父ID为128的所有目录,既婴儿车的父目录找到了。
在这里插入图片描述
后续按照这个思路重新写程序能够实现三级分类展现所有子目录的功能,但是对bug产生的原因不太清晰!!!

解决方法:加上(long)向下转型自动拆箱

改变一行代码
在这里插入图片描述
就是因为递归调用了太多次,自动装箱成Long对象,但是Long对象装箱的源码实现跟128有很大的关系!! 下面解释中的Integer是一个道理,(Integer) 128 == (Integer) 128 为false,所以128之后的二级目录都不满足这个判断,所以他们的三级目录无法加载!!!
具体代码实现可以看引用!!!

Integer类 -128~127 之间的值都是直接从缓存中取出的,(Integer)127 == (Integer)127两边装箱后,实际指向堆内存中同一个对象,大于127 后就new一个新的对象返回。(Integer)128 == (Integer)128,装箱为引用类型后,没有做缓存,指向堆内存中不同对象,所以比较结果为false。至于为什么要缓存,若不缓存,每次都要new一个新对象,资源消耗多,所以缓存一些常用的数,来减少资源损耗。
————————————————
版权声明:本文为CSDN博主「有时候我也会」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/weixin_43849277/article/details/108275997

总结: 递归使用要慎重,自动装箱的隐藏机制需要熟悉

开发过程中不要随便用递归!!!Debug不好调整,遇到其他问题结合,真的是头皮发麻!!!本文只是精简的讲述了核心找bug的过程,但是Debug打各种条件断点,查看Tomcat源码,StackFlow看英文,,,等等困扰了我一天的bug,终于跟冠哥合理解决了!!!

推荐看一下阿里开发手册对递归使用的建议!!!

http://www.yayakq.cn/news/45442/

相关文章:

  • 网站建设 源代码wordpress add_menu_page
  • 开个网站卖机器怎么做企业app开发企业
  • 遂宁网站建设公司哪家好wordpress安全插件下载
  • 上海网站建设中小型企业世界工厂网免费平台
  • 做告状网站坂田网站建设方案
  • 做网站是不是太麻烦了京网站建设
  • 免费公司网站主页模板昆明网络营销线上广告
  • dw制作简单网站模板下载地址网站建设公司画册
  • 深圳住建设局网站公司注册公司哪个好
  • wordpress分站百度网站怎样做推广
  • 做废旧回收哪个网站好阿里巴巴国际贸易网站官网
  • 校园视频网站建设雅安网站制作
  • wordpress漫画网站小鸟云服务器官网
  • 安徽外贸网站google建站自己做的网站申请软著
  • 做信息网站要办icp证吗百度小程序关键词优化
  • 越秀营销型网站wordpress cpanel
  • 注册网站用什么邮箱南昌建网站
  • 福州企业网站推广定制肇庆企业网站关键词优化教程
  • wordpress wp_editor长沙网站优化推广
  • 天空在线网站建设嵌入式软件开发基础实训总结
  • 工信部isp申请网站wordpress插件 占用内存
  • 运城做网站哪家好十大高端网站定制设计
  • 模板网页文档的默认扩展名为企业网站怎么搜索优化
  • 上海做网站的公司电话会员制营销的优缺点
  • 企业网站部署计划芜湖市住房和城乡建设厅网站首页
  • 网站内容设计要求中国最大的销售网站
  • 可以推广网站应用软件下载app
  • 整站seo运营域名访问网址
  • 网站开发工具 售价2013深圳网站设计公司排名
  • 化妆品手机端网站模板seo短视频入口