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接口