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

宁德网站开发有没有免费的网站空间

宁德网站开发,有没有免费的网站空间,工作是工作,wordpress商店团购主题项目中使用了很多树状结构,为了方便使用开发一个通用的工具类。 使用工具类的时候写一个类基础BaseNode,如果有个性化字段添加到类里面,然后就可以套用工具类。 工具类会将id和pid做关联返回一个树状结构的集合。 使用了hutool的工具包判空…

项目中使用了很多树状结构,为了方便使用开发一个通用的工具类。

使用工具类的时候写一个类基础BaseNode,如果有个性化字段添加到类里面,然后就可以套用工具类。

工具类会将id和pid做关联返回一个树状结构的集合。

使用了hutool的工具包判空。

TreeUtil.java

import cn.hutool.core.util.ObjUtil;
import com.iccb.BaseNode;import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;public class TreeUtil {public static <T extends BaseNode<T>> List<T> toTree(List<T> treeNodeList) {//数据按照pid分组Map<Long, List<T>> map = treeNodeList.stream().collect(Collectors.groupingBy(T :: getPid,LinkedHashMap::new,Collectors.toList()));//找出所有的根节点,pid=-1的为根节点List<T> areaList = map.get(-1L);if(ObjUtil.isEmpty(areaList)){return new ArrayList<>();}for (T areaVO : areaList) {forEach(map, areaVO);}return areaList;}private static  <T extends BaseNode<T>> void forEach(Map<Long, List<T>> collect, T areaVO) {List<T> nodeList = collect.get(areaVO.getId());if (collect.get(areaVO.getId()) == null) {return;}areaVO.setChildren(nodeList);for (T node : nodeList) {forEach(collect, node);}}}

 BaseNode.java

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;import java.io.Serializable;
import java.util.List;/*** @author admin*/
@Data
public class BaseNode<T> implements Serializable {private static final long serialVersionUID = 1L;@JsonFormat(shape = JsonFormat.Shape.STRING)private Long id;@JsonFormat(shape = JsonFormat.Shape.STRING)private Long pid;private String value;private List<T> children;
}

 使用范例

返回树状结构的地区数据

1)首先构建数据VO

@EqualsAndHashCode(callSuper = true)
@Data
public class AreaVO extends BaseNode<AreaVO> {private static final long serialVersionUID = 1L;private String areaCode;private String label;private String level;private String lnglat;}

2)查询地区数据

List<Area> list = areaService.list();

3) 构建数据VO 或者 直接使用mapper查询用VO封装

List<AreaVO> collect = list.stream().map(i -> {AreaVO areaVO = BeanUtil.copyProperties(i, AreaVO.class);areaVO.setLabel(i.getAreaName());areaVO.setValue(String.valueOf(i.getId()));areaVO.setLevel(i.getAreaLevel());areaVO.setPid(i.getParentId());return areaVO;
}).collect(Collectors.toList());

4) 使用工具类构造数据结构

List<AreaVO> areaTree = TreeUtil.toTree(collect);

数据返回示例

{"code": 200,"msg": null,"data": [{"id": "4058069977868140544","value": "4058069977868140544","pid": "4058069977868148888","children": [{"id": "4058069978245627904","value": "4058069978245627904","pid": "4058069977868140544","children": [{"id": "4058069978530840576","value": "4058069978530840576","pid": "4058069978245627904","children": null,"areaCode": "110101000000","label": "东城区","level": "3","lnglat": null},{"id": "4058069978732167168","value": "4058069978732167168","pid": "4058069978245627904","children": null,"areaCode": "110102000000","label": "西城区","level": "3","lnglat": null},{"id": "4058069978874773504","value": "4058069978874773504","pid": "4058069978245627904","children": null,"areaCode": "110105000000","label": "朝阳区","level": "3","lnglat": null},{"id": "4058069978979631104","value": "4058069978979631104","pid": "4058069978245627904","children": null,"areaCode": "110106000000","label": "丰台区","level": "3","lnglat": null},{"id": "4058069979046739968","value": "4058069979046739968","pid": "4058069978245627904","children": null,"areaCode": "110107000000","label": "石景山区","level": "3","lnglat": null},{"id": "4058069979118043136","value": "4058069979118043136","pid": "4058069978245627904","children": null,"areaCode": "110108000000","label": "海淀区","level": "3","lnglat": null},{"id": "4058069979231289344","value": "4058069979231289344","pid": "4058069978245627904","children": null,"areaCode": "110109000000","label": "门头沟区","level": "3","lnglat": null},{"id": "4058069979336146944","value": "4058069979336146944","pid": "4058069978245627904","children": null,"areaCode": "110111000000","label": "房山区","level": "3","lnglat": null},{"id": "4058069979441004544","value": "4058069979441004544","pid": "4058069978245627904","children": null,"areaCode": "110112000000","label": "通州区","level": "3","lnglat": null},{"id": "4058069979550056448","value": "4058069979550056448","pid": "4058069978245627904","children": null,"areaCode": "110113000000","label": "顺义区","level": "3","lnglat": null},{"id": "4058069979650719744","value": "4058069979650719744","pid": "4058069978245627904","children": null,"areaCode": "110114000000","label": "昌平区","level": "3","lnglat": null},{"id": "4058069979747188736","value": "4058069979747188736","pid": "4058069978245627904","children": null,"areaCode": "110115000000","label": "大兴区","level": "3","lnglat": null},{"id": "4058069979852046336","value": "4058069979852046336","pid": "4058069978245627904","children": null,"areaCode": "110116000000","label": "怀柔区","level": "3","lnglat": null},{"id": "4058069979956903936","value": "4058069979956903936","pid": "4058069978245627904","children": null,"areaCode": "110117000000","label": "平谷区","level": "3","lnglat": null},{"id": "4058069980166619136","value": "4058069980166619136","pid": "4058069978245627904","children": null,"areaCode": "110228000000","label": "密云区","level": "3","lnglat": null},{"id": "4058069980284059648","value": "4058069980284059648","pid": "4058069978245627904","children": null,"areaCode": "110229000000","label": "延庆区","level": "3","lnglat": null}],"areaCode": "110100000000","label": "北京市","level": "2","lnglat": null}],"areaCode": "110000000000","label": "北京市","level": "1","lnglat": null},{"id": "4058069980422471680","value": "4058069980422471680","pid": "4058069977868148888","children": [{"id": "4058069980527329280","value": "4058069980527329280","pid": "4058069980422471680","children": [{"id": "4058069980627992576","value": "4058069980627992576","pid": "4058069980527329280","children": null,"areaCode": "120101000000","label": "和平区","level": "3","lnglat": null},{"id": "4058069980732850176","value": "4058069980732850176","pid": "4058069980527329280","children": null,"areaCode": "120102000000","label": "河东区","level": "3","lnglat": null},{"id": "4058069980841902080","value": "4058069980841902080","pid": "4058069980527329280","children": null,"areaCode": "120103000000","label": "河西区","level": "3","lnglat": null},{"id": "4058069980938371072","value": "4058069980938371072","pid": "4058069980527329280","children": null,"areaCode": "120104000000","label": "南开区","level": "3","lnglat": null},{"id": "4058069981043228672","value": "4058069981043228672","pid": "4058069980527329280","children": null,"areaCode": "120105000000","label": "河北区","level": "3","lnglat": null},{"id": "4058069981148086272","value": "4058069981148086272","pid": "4058069980527329280","children": null,"areaCode": "120106000000","label": "红桥区","level": "3","lnglat": null},{"id": "4058069981252943872","value": "4058069981252943872","pid": "4058069980527329280","children": null,"areaCode": "120110000000","label": "东丽区","level": "3","lnglat": null},{"id": "4058069981357801472","value": "4058069981357801472","pid": "4058069980527329280","children": null,"areaCode": "120111000000","label": "西青区","level": "3","lnglat": null},{"id": "4058069981475241984","value": "4058069981475241984","pid": "4058069980527329280","children": null,"areaCode": "120112000000","label": "津南区","level": "3","lnglat": null},{"id": "4058069981580099584","value": "4058069981580099584","pid": "4058069980527329280","children": null,"areaCode": "120113000000","label": "北辰区","level": "3","lnglat": null},{"id": "4058069981684957184","value": "4058069981684957184","pid": "4058069980527329280","children": null,"areaCode": "120114000000","label": "武清区","level": "3","lnglat": null},{"id": "4058069981789814784","value": "4058069981789814784","pid": "4058069980527329280","children": null,"areaCode": "120115000000","label": "宝坻区","level": "3","lnglat": null},{"id": "4058069981890478080","value": "4058069981890478080","pid": "4058069980527329280","children": null,"areaCode": "120116000000","label": "滨海新区","level": "3","lnglat": null},{"id": "4058069981986947072","value": "4058069981986947072","pid": "4058069980527329280","children": null,"areaCode": "120117000000","label": "宁河区","level": "3","lnglat": null},{"id": "4058069982087610368","value": "4058069982087610368","pid": "4058069980527329280","children": null,"areaCode": "120118000000","label": "静海区","level": "3","lnglat": null},{"id": "4058069982293131264","value": "4058069982293131264","pid": "4058069980527329280","children": null,"areaCode": "120225000000","label": "蓟州区","level": "3","lnglat": null}],"areaCode": "120100000000","label": "天津市","level": "2","lnglat": null}],"areaCode": "120000000000","label": "天津市","level": "1","lnglat": null},{"id": "4461100398823866368","value": "4461100398823866368","pid": "4058069977868148888","children": [{"id": "4461100398974861312","value": "4461100398974861312","pid": "4461100398823866368","children": null,"areaCode": "820100000000","label": "澳门半岛","level": "2","lnglat": null},{"id": "4461100399113273344","value": "4461100399113273344","pid": "4461100398823866368","children": null,"areaCode": "820200000000","label": "离岛","level": "2","lnglat": null}],"areaCode": "820000000000","label": "澳门特别行政区","level": "1","lnglat": null}]
}


文章转载自:

http://HhiD9kRx.jtrqn.cn
http://sW4swVCL.jtrqn.cn
http://rJf1nlyV.jtrqn.cn
http://DGs0m2Xv.jtrqn.cn
http://JWjcAERH.jtrqn.cn
http://pGTIafuy.jtrqn.cn
http://iJnsdWm8.jtrqn.cn
http://Rm0tlZin.jtrqn.cn
http://DpIDlWMS.jtrqn.cn
http://LG8pcv7I.jtrqn.cn
http://wC98heo4.jtrqn.cn
http://klFlCJwR.jtrqn.cn
http://DeCMrLiq.jtrqn.cn
http://kMIEQpvn.jtrqn.cn
http://3INlrNNY.jtrqn.cn
http://7mADUj1Y.jtrqn.cn
http://ZUCXcaJX.jtrqn.cn
http://5OjZCkkU.jtrqn.cn
http://ttjiyYig.jtrqn.cn
http://oiDqcPWy.jtrqn.cn
http://QAIwNKjg.jtrqn.cn
http://66orJxid.jtrqn.cn
http://fTTg0Fsd.jtrqn.cn
http://4zrlLald.jtrqn.cn
http://DU4MqQa0.jtrqn.cn
http://bGMcNXaE.jtrqn.cn
http://SOV8CGCn.jtrqn.cn
http://e9BPPvip.jtrqn.cn
http://BLUixLXV.jtrqn.cn
http://IvqqO3Rg.jtrqn.cn
http://www.dtcms.com/wzjs/707774.html

相关文章:

  • 网站建立的重要性专业做书画推广的网站
  • wordpress网站内容地方网站怎么做挣钱
  • 特效相册网站源码上海做网站优化哪家好
  • 在手机上创建网站吗wordpress调用标签代码在线
  • 织梦网站防黑怎么做做网站做系统一样么
  • 如何用vc做网站基于iview的网站开发模板
  • 创建一个网站的项目体现项目完成速度因素的专门发布采购信息的网站
  • 做网站在哪买域名搬瓦工暗转wordpress
  • 徐州市贾汪区建设局网站设计网站多少钱
  • 网站规划与设计大作业郑州旅游网站建设
  • 乐成高端网站建设国外网站问题
  • 宝安官网网站建设比较好的js网站模板下载
  • 制作网页与网站库存管理软件免费版
  • 企业网站源码哪个最好高校网站建设目的与意义
  • 莱芜住房和城乡建设厅网站福建省住房和建设厅网站
  • 行业网站的特点建立网站的作用
  • 格力空调网站建设策划书徐州企业建站模板
  • 做网站哪家公司比较好手机网站与电脑网站的区别
  • 潍坊品牌网站建设专业企业网站建设定制
  • 欧美网站设计欣赏win7系统做网站服务器
  • 网站开发维护合同样板百度推广获客成本大概多少
  • 自定义网站建设南皮做网站价格
  • 厦门市建设质量安全协会网站网站开发的研究方法
  • 微信视频网站怎么做的好网站开发毕设论文
  • 服务器除了做网站还能做什么湖南有实力seo优化
  • 部队网站建设招标.la域名做的网站
  • 标准网站建设做网站的分辨率
  • 大型网站解决方案设计门户网站平台建设情况
  • 最新聊天记录做图网站购物网站开发
  • 创业中文网站模板上海专业做网站公司报价