TreeNode实现Java列表转树形结构列表
2021-05-06 01:27
标签:src varchar ESS const charset mapper als request getch TreeNode实现Java列表转树形结构列表 标签:src varchar ESS const charset mapper als request getch 原文地址:https://www.cnblogs.com/weigy/p/13191327.html表结构
CREATE TABLE `test2` (
`id` varchar(32) DEFAULT NULL,
`prarentid` varchar(32) DEFAULT NULL,
`name` varchar(255) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
实体类
@Data
public class Test2 {
private String id;
private String parentid;
private String name;
}
访问数据接口
@Mapper
public interface Test2Mapper {
List
业务实现类
@Service
@Slf4j
public class Test2Service {
@Autowired
private Test2Mapper test2Mapper;
public List
控制层类
@Api(value = "TEST2管理", tags = {"TEST2管理"})
@RestController
@Slf4j
@RequestMapping("/test")
public class Test2Controller {
@Autowired
private Test2Service test2Service;
@ApiOperation(value = "树形结构列表")
@GetMapping("/list")
public ResponseEntity listUser() {
TreeNode node = new TreeNode();
List
接口公共返回实体
@Data
public class ResponseEntity {
//返回编码
private String msgCode;
//返回信息
private String message;
//返回的数据
private Object data;
}
TreeNode工具类
package com.sb.util;
import java.util.ArrayList;
/**
* TreeNode 工具类
*/
public class TreeNode {
private String uuid;
private String parentUuid;
private String tagUuid;
private String poiName;
private ArrayList
接口请求结果
{
"msgCode": "1000",
"message": "操作成功",
"data": [
{
"uuid": "1",
"parentUuid": null,
"tagUuid": "1",
"poiName": "老三",
"children": [
{
"uuid": "2",
"parentUuid": "1",
"tagUuid": "2",
"poiName": "老四",
"children": [
{
"uuid": "3",
"parentUuid": "2",
"tagUuid": "3",
"poiName": "老五",
"children": []
}
]
}
]
}
]
}
文章标题:TreeNode实现Java列表转树形结构列表
文章链接:http://soscw.com/index.php/essay/82984.html