我在Neo4jRepository
中有以下自定义查询(我正在使用带有Spring Data Neo4j的Spring Boot):
@Query("MATCH (n:Component) WHERE n.path =~ '/path/{0}/.*/{1}' RETURN n")
Component findByTenantAndName(String tenant, String name);
当我在应用程序中运行此查询时,它返回null
并带有以下日志语句:
2018-01-12 10:58:27.744 INFO 74294 --- [nio-8080-exec-1] o.n.o.drivers.bolt.request.BoltRequest : Request: MATCH (n:Component) WHERE n.path =~ '/path/{0}/.*/{1}' RETURN n with params {0=foo, 1=baz}
2018-01-12 10:58:27.763 WARN 74294 --- [nio-8080-exec-1] d.c.a.service.MyService : Could not find parent component named 'baz' for tenant 'foo'
但是,如果我在http://localhost:7474转到Cypher后端并运行查询:
MATCH (n:Component) WHERE n.path =~ '/path/foo/.*/baz' RETURN n
我只用路径Component
得到一个/path/foo/bar/baz
结果。我的自定义查询有什么问题?
答案 0 :(得分:2)
@Query("MATCH (n:Component) WHERE n.path =~ {0} RETURN n")
Component findByTenantAndName(String query);
从你称之为的服务。像这样传递整个正则表达式
String query = "/path/<tenant>/.*/<name>"; // replace tenant and name with actual variables.
findByTenantAndName(query)