Java 操作 Znode 节点
Jihongchang(讨论 | 贡献)2022年8月17日 (三) 11:33的版本
查询
package org.example;
import org.apache.curator.framework.CuratorFramework;
import org.junit.Test;
import java.util.List;
public class Demo2 {
    CuratorFramework cf = ZkUtil.cf();
    /**
     * 查询子节点
     * @throws Exception
     */
    @Test
    public void getChildren() throws Exception {
        List<String> strings = cf.getChildren().forPath("/");
        for (String string : strings) {
            System.out.println(string);
        }
    }
    /**
     * 查询子节点数据
     * @throws Exception
     */
    @Test
    public void getData() throws Exception {
        byte[] bytes = cf.getData().forPath("/qf");
        System.out.println(new String(bytes, "UTF-8"));
    }
}
添加
......
    /**
     * 创建新节点
     * @throws Exception
     */
    @Test
    public void create() throws Exception {
        cf.create().withMode(CreateMode.PERSISTENT).forPath("/qf2", "uuuu".getBytes());
    }
......