NonNullApi 使用
1. 当参数传null 时将抛出异常,除非用 @Nullable
2. 当返回值为null 时将抛出异常,除非用 @Nullable ,也能够用 Optional 包裹html
@NonNullApi package org.canaan.neo4j.graph; import org.springframework.lang.NonNullApi;
继承 Neo4jRepository 接口java
package org.canaan.neo4j.graph; import org.canaan.neo4j.graph.entity.UserNode; import org.springframework.data.neo4j.annotation.Depth; import org.springframework.data.neo4j.annotation.Query; import org.springframework.data.neo4j.repository.Neo4jRepository; import org.springframework.data.repository.query.Param; import org.springframework.lang.Nullable; import java.util.Optional; /** * @author Canaan * @date 2019/7/11 8:47 */ public interface UserNeo4jDao extends Neo4jRepository<UserNode, Long> { //@Query("MATCH (n:User{id:{0}}) RETURN n ") Optional<UserNode> findByUserId(Long userId); Optional<UserNode> findByUserId(@Param("userId") Long userId, @Depth int depth); @Query("MATCH p=(n:User) -->() WHERE n.userId = {0} RETURN p ") Optional<UserNode> findPathByUserId(Long userId); @Nullable Optional<UserNode> findByUserName(@Nullable String userName); @Query("MATCH (movie:Movie)-[r:RATING]\->(), (movie)<-[:ACTS_IN]-(actor:Actor) " + "WHERE movie.id={0} " + "RETURN movie as movie, COLLECT(actor) AS 'cast', AVG(r.stars) AS 'averageRating'") MovieData getMovieData(String movieId); @QueryResult public class MovieData { Movie movie; Double averageRating; Set<Actor> cast; } }
查询相差的注解能够在 org.springframework.data.neo4j.annotation 包下找到spring
主要 注解 有 @Query @Param @Depth @QueryResult .net
官方文档:code
https://docs.spring.io/spring-data/neo4j/docs/5.1.3.RELEASE/reference/html/#_usagehtm
接口中方法命名规则:继承
https://docs.spring.io/spring-data/neo4j/docs/5.1.3.RELEASE/reference/html/#_query_methods接口