CREATE TABLE t_area (
id int(0) NOT NULL AUTO_INCREMENT,
parent_id int(0) NULL DEFAULT NULL,
name varchar(255) NULL DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 10 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;
INSERT INTO `t_area`(`id`, `parent_id`, `name`) VALUES (1, 0, '福建省');
INSERT INTO `t_area`(`id`, `parent_id`, `name`) VALUES (2, 1, '泉州市');
INSERT INTO `t_area`(`id`, `parent_id`, `name`) VALUES (3, 1, '福州市');
INSERT INTO `t_area`(`id`, `parent_id`, `name`) VALUES (4, 1, '厦门市');
INSERT INTO `t_area`(`id`, `parent_id`, `name`) VALUES (5, 2, '丰泽区');
INSERT INTO `t_area`(`id`, `parent_id`, `name`) VALUES (6, 2, '鲤城区');
INSERT INTO `t_area`(`id`, `parent_id`, `name`) VALUES (7, 4, '思明区');
INSERT INTO `t_area`(`id`, `parent_id`, `name`) VALUES (8, 4, '湖里区');
INSERT INTO `t_area`(`id`, `parent_id`, `name`) VALUES (9, 4, '翔安区');
INSERT INTO `t_area`(`id`, `parent_id`, `name`) VALUES (10, 7, '莲前街道');
with recursive t as
select * from t_area where name = '厦门市'
union all
select a.* from t_area a join t on a.parent_id = t.id
select * from t
- 结果如下。其中,莲前街道为思明区的子集,也会一起查询出来
查出当前父级数据,以及父级的父级,父级的父级的父级,等等
with recursive t as
select * from t_area where name = '莲前街道'
union all
select a.* from t_area a join t on a.id = t.parent_id
select * from t
比如是一个 id 为 test 的 div元素,我们这样选中,$('#test'),我们要查找这个div下的一个class为demo的span元素,有一下几种方法
1、使用筛选条件
$('#test span.demo')
2、使用find()函数
$('#test').find('span.demo')
3、使用children()函数
$('#test').ch
public static Label getParentLabelObject(Label label,List<Label> list) {
if (label.getParentId() == 0) {
return label;
Label l = list.strea...