“Java 操作 Znode 节点”的版本间的差异
跳到导航
跳到搜索
Jihongchang(讨论 | 贡献) |
Jihongchang(讨论 | 贡献) |
||
第1行: | 第1行: | ||
=== 查询 === | === 查询 === | ||
+ | <syntaxhighlight lang="java"> | ||
+ | package org.example; | ||
+ | |||
+ | import org.apache.curator.framework.CuratorFramework; | ||
+ | import org.junit.Test; | ||
+ | |||
+ | import java.util.List; | ||
+ | |||
+ | public class Demo2 { | ||
+ | |||
+ | CuratorFramework cf = ZkUtil.cf(); | ||
+ | |||
+ | @Test | ||
+ | public void getChildren() throws Exception { | ||
+ | List<String> strings = cf.getChildren().forPath("/"); | ||
+ | for (String string : strings) { | ||
+ | System.out.println(string); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | @Test | ||
+ | public void getData() throws Exception { | ||
+ | byte[] bytes = cf.getData().forPath("/qf"); | ||
+ | System.out.println(new String(bytes, "UTF-8")); | ||
+ | } | ||
+ | |||
+ | } | ||
+ | |||
+ | </syntaxhighlight> | ||
=== 添加 === | === 添加 === |
2022年8月17日 (三) 11:23的版本
查询
package org.example;
import org.apache.curator.framework.CuratorFramework;
import org.junit.Test;
import java.util.List;
public class Demo2 {
CuratorFramework cf = ZkUtil.cf();
@Test
public void getChildren() throws Exception {
List<String> strings = cf.getChildren().forPath("/");
for (String string : strings) {
System.out.println(string);
}
}
@Test
public void getData() throws Exception {
byte[] bytes = cf.getData().forPath("/qf");
System.out.println(new String(bytes, "UTF-8"));
}
}