这是我想要的数据格式
public Node initializService (String minderId){
Node node = new Node();
RootMind rootMind=new RootMind();
//根据思维导图根节点id查出根节点下所有属性
MindPo po = mindMapper.selectByMindId(minderId);
//创建vo对象,用来接收根节点返回值
if (po != null) {
node.setTemplate(po.getTemplate());
node.setTheme(po.getTheme());
MindVO vo = new MindVO();
vo.setId(po.getId());
vo.setCreated(po.getCreated());
vo.setExpandState(po.getExpandState());
vo.setImage(po.getImage());
vo.setNote(po.getNote());
vo.setText(po.getText());
vo .setPriority(po.getPriority());
vo.setProgress(po.getProgress());
vo.setHyperlink(po.getHyperlink());
vo.setHyperlinkTitle(po.getHyperlinkTitle());
vo.setTheme(po.getTheme());
vo.setTemplate(po.getTemplate());
ImgSize imgSize = new ImgSize();
imgSize.setImgSizeWidth(po.getImgSizeWidth());
imgSize.setImgSizeWidth(po.getImgSizeHeight());
vo.setImgSize(imgSize);
//创建rootmind,把根节点存放到data数据里
rootMind.setData(vo);
//根据根节点id查找根节点下的所有子节点,进行递归操作。
List<RootMind> rootMindList =webService.selectChildrenByParent(po.getId());
rootMind.setChildren(rootMindList);
node.setRoot(rootMind);
}
node.setRoot(rootMind);
return node;
}
//递归子节点
public List<RootMind> selectChildrenByParent(String parentId) {
//rootMindList用来存储要返回的数据格式
List<RootMind> rootMindList =new ArrayList<>();
//根据parentId查询所有子节点,不确定有多少个节点,故用list接收
List<MindVO> mindVOList=this.mindMapper.selectChildrenByParent(parentId);
if (mindVOList.size()==0){
return null;
}
for (MindVO mindVO:mindVOList){
//判断子节点下的子节点是否有子节点
List<RootMind> rootMindChildren = webService.selectChildrenByParent(mindVO.getId());
//是空则证明下边没有子节点
if(rootMindChildren == null){
RootMind rootMind = new RootMind();
rootMind.setData(mindVO);
//因如果此节点下没有子节点,需插入一个空数组(rootMind2)来完善样式。
List<RootMind>rootMindNull = new ArrayList<>();
rootMind.setChildren(rootMindNull);
rootMindList.add(rootMind);
}else{
RootMind rootMind = new RootMind();
rootMind.setChildren(rootMindChildren);
rootMind.setData(mindVO);
rootMindList.add(rootMind);
}
}
return rootMindList;
}
@Data
public class RootMind {
private MindVO data;
private List<RootMind> children;
}
俺又写了一种思路
public List<RootMind> selectChildrenByParent(String parentId) {
List<RootMind> rootMindList =new ArrayList<>();
//根据parentId查询所有子节点,不确定有多少个节点,故用list接收
List<MindVO> mindVOList=this.mindMapper.selectChildrenByParent(parentId);
if (mindVOList.size()==0){
return null;
}
for (MindVO mindVO:mindVOList){
//判断子节点下的子节点是否有子节点
List<RootMind> rootMindChildren = this.selectChildrenByParent(mindVO.getId());
//是空则证明下边没有子节点
if(rootMindChildren == null){
RootMind rootMind = new RootMind();
Map<String,Object> mapChildren = new HashMap<>();
mapChildren.put("id",mindVO.getId());
mapChildren.put("created",mindVO.getCreated());
mapChildren.put("note",mindVO.getNote());
mapChildren.put("text",mindVO.getText());
mapChildren.put("image",mindVO.getImage());
mapChildren.put("imageTitle",mindVO.getImageTitle());
ImgSize imgSize = new ImgSize();
imgSize.setImgSizeWidth(mindVO.getImgSizeWidth());
imgSize.setImgSizeWidth(mindVO.getImgSizeHeight());
mapChildren.put("imageSize",imgSize);
mapChildren.put("hyperlink",mindVO.getHyperlink());
mapChildren.put("hyperlinkTitle",mindVO.getHyperlinkTitle());
mapChildren.put("font-size",mindVO.getFontSize());
mapChildren.put("font-family",mindVO.getFontFamily());
mapChildren.put("font-style",mindVO.getFontStyle());
mapChildren.put("font-weight",mindVO.getFontWeight());
mapChildren.put("priority",mindVO.getPriority());
mapChildren.put("progress",mindVO.getProgress());
mapChildren.put("color",mindVO.getColor());
rootMind.setData(mapChildren);
//因如果此节点下没有子节点,需插入一个空数组(rootMind2)来完善样式。
List<RootMind>rootMindNull = new ArrayList<>();
rootMind.setChildren(rootMindNull);
rootMindList.add(rootMind);
}else{
RootMind rootMind = new RootMind();
rootMind.setChildren(rootMindChildren);
Map<String,Object> mapChildren = new HashMap<>();
mapChildren.put("id",mindVO.getId());
mapChildren.put("created",mindVO.getCreated());
mapChildren.put("text",mindVO.getText());
mapChildren.put("image",mindVO.getImage());
mapChildren.put("imageTitle",mindVO.getImageTitle());
ImgSize imgSize = new ImgSize();
imgSize.setImgSizeWidth(mindVO.getImgSizeWidth());
imgSize.setImgSizeWidth(mindVO.getImgSizeHeight());
mapChildren.put("imageSize",imgSize);
mapChildren.put("hyperlink",mindVO.getHyperlink());
mapChildren.put("hyperlinkTitle",mindVO.getHyperlinkTitle());
mapChildren.put("font-size",mindVO.getFontSize());
mapChildren.put("font-family",mindVO.getFontFamily());
mapChildren.put("font-style",mindVO.getFontStyle());
mapChildren.put("font-weight",mindVO.getFontWeight());
mapChildren.put("priority",mindVO.getPriority());
mapChildren.put("progress",mindVO.getProgress());
mapChildren.put("color",mindVO.getColor());
rootMind.setData(mapChildren);
rootMindList.add(rootMind);
}
}
return rootMindList;
}
public Node initializService (String minderId){
Node node = new Node();
RootMind rootMind=new RootMind();
//根据思维导图根节点id查出根节点下所有属性
MindPo po = mindMapper.selectByMindId(minderId);
//创建vo对象,用来接收根节点返回值
if (po != null) {
node.setTemplate(po.getTemplate());
node.setTheme(po.getTheme());
Map<String,Object> map = new HashMap<>();
map.put("id",po.getId());
map.put("created",po.getCreated());
map.put("text",po.getText());
map.put("image",po.getImage());
ImgSize imgSize = new ImgSize();
imgSize.setImgSizeWidth(po.getImgSizeWidth());
imgSize.setImgSizeWidth(po.getImgSizeHeight());
map.put("imageSize",imgSize);
map.put("hyperlink",po.getHyperlink());
map.put("hyperlinkTitle",po.getHyperlinkTitle());
map.put("font-size",po.getFontSize());
map.put("font-family",po.getFontFamily());
map.put("font-style",po.getFontStyle());
map.put("font-weight",po.getFontWeight());
map.put("priority",po.getPriority());
map.put("progress",po.getProgress());
map.put("color",po.getColor());
map.put("note",po.getNote());
rootMind.setData(map);
//根据根节点id查找根节点下的所有子节点,进行递归操作。
List<RootMind> rootMindList =this.selectChildrenByParent(po.getId());
rootMind.setChildren(rootMindList);
node.setRoot(rootMind);
}
// node.setRoot(rootMind);
return node;
}