Nebula Graph介绍和SpringBoot环境连接和查询( 三 )

辅助类 NebulaResult.java 等外层结构这里定义了 json 格式响应的外层结构
@Datapublic class NebulaResult<T> implements Serializable {private List<Error> errors;private List<Result<T>> results;@JsonIgnorepublic boolean isSuccess() {return (errors != null && errors.size() == 1 && errors.get(0).getCode() == 0);}@Datapublic static class Error implements Serializable {private int code;}@Data@JsonIgnoreProperties(ignoreUnknown = true)@JsonInclude(JsonInclude.Include.NON_NULL)public static class Result<T> implements Serializable {private String spaceName;private List<Element<T>> data;private List<String> columns;private Error errors;private long latencyInUs;}@Datapublic static class Element<T> implements Serializable {private List<Meta<T>> meta;private List<Serializable> row;}@Datapublic static class Meta<T> implements Serializable {private String type;private T id;}}内层因为区分Edge和Vertex, 结构不一样. 如果是混合返回的结果, 可以用 Serializable
String gql = "match (v:ADDR)-[e]-() where id(v)==\"ADD:123123\" return v,e limit 100";NebulaResult<Serializable> res = graphService.query("insurance", gql);log.info(JacksonUtil.compress(res));Assertions.assertThat(res).isNotNull();对于边, 需要使用结构化的ID
@Data@JsonIgnoreProperties(ignoreUnknown = true)@JsonInclude(JsonInclude.Include.NON_NULL)public class EdgeId implements Serializable {private int ranking;private int type;private String dst;private String src;private String name;}用这个结构进行查询
NebulaResult<EdgeId> res3 = graphService.query("t_test1", "MATCH ()-[e:follow]-() RETURN e");对于点, ID就是String
NebulaResult<String> res2 = graphService.query("t_test1", "MATCH (v:player) RETURN v");

经验总结扩展阅读