php富文本预览,富文本中代码预览测试(Ueditor)

该博客主要展示了如何使用Java和Spring框架,通过递归方式查询数据库获取树形结构数据,并进行性能优化。文章中详细解释了如何利用DAO层查询根节点及其所有子节点,以及在查询过程中如何处理节点类型和子节点集合。同时,还记录了查询过程的耗时,强调了在处理大量数据时的效率问题。
摘要由CSDN通过智能技术生成

package com.sunwayland.websocket.service;

import com.fasterxml.jackson.core.JsonProcessingException;

import com.fasterxml.jackson.databind.ObjectMapper;

import com.sunwayland.websocket.dao.TbPointDao;

import com.sunwayland.websocket.entity.TbPoint;

import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Service;

import java.util.ArrayList;

import java.util.List;

@Service

@Slf4j

public class PsaceServiceImpl {

@Autowired

private ObjectMapper objectMapper;

@Autowired

private TbPointDao tbPointDao;

public String queryAllPoints() throws JsonProcessingException {

long startTime = System.currentTimeMillis();

TbPoint rootPoint = new TbPoint();

rootPoint.setId(0);

//查询根节点

List roots = tbPointDao.queryAllPointByParentId(rootPoint);

TbPoint rootNodePoint = roots.get(0);

// 第一级节点的集合

List firstLevelNodePointList = tbPointDao.queryAllPointByParentId(rootNodePoint);

if(firstLevelNodePointList.size() > 0){

iterator(firstLevelNodePointList);

rootNodePoint.setTbPointList(firstLevelNodePointList);

}

long endTime = System.currentTimeMillis();

long spendTime = (endTime - startTime)/ 1000;

String result = "查询所有节点:共耗时=" + spendTime + " S";

log.info(result);

List tbPointList = new ArrayList<>();

tbPointList.add(rootNodePoint);

return objectMapper.writeValueAsString(tbPointList);

}

public void iterator(List nodePointList){

for(int i = 0; i 

TbPoint rootNodePoint = nodePointList.get(i);

//            byte pointType = 2;

//            rootNodePoint.setPointType(pointType);

Integer childCount = tbPointDao.findCount(rootNodePoint);

if(childCount != null){

List childNodePointList = tbPointDao.queryAllPointByParentIdAndPointType(rootNodePoint);

Boolean isHasNode = false;

//如果子节点数大于 0,且子节点中有类型为Node的节点,则需要对子节点集合进行迭代,否则停止

if(childNodePointList.size() > 0){

for(int j = 0; j 

TbPoint childPoint = childNodePointList.get(j);

if(childPoint.getPointType() == 0){

isHasNode = true;

break;

}

}

}

if(isHasNode){

iterator(childNodePointList);

}

nodePointList.get(i).setTbPointList(childNodePointList);

}

}

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值