整整折腾了三天,终于把spring boot + neo4j的路走通了。

这里介绍3个部分,pom,entity,repository

1)pom

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <groupId>com.company.project</groupId>
<artifactId>knowledge</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>Maven Webapp</name> <parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.0.RELEASE</version>
</parent> <properties>
<java.version>1.7</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties> <dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-neo4j</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
</dependency> <dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.1.41</version>
</dependency> </dependencies> <build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
    <mainClass>com.bonc.knowledge.Startup</mainClass>
   </configuration>
</plugin>
</plugins>
</build> </project>

2)entity

import java.util.HashSet;
import java.util.Set; import org.neo4j.graphdb.Direction;
import org.springframework.data.neo4j.annotation.Fetch;
import org.springframework.data.neo4j.annotation.GraphId;
import org.springframework.data.neo4j.annotation.Indexed;
import org.springframework.data.neo4j.annotation.NodeEntity;
import org.springframework.data.neo4j.annotation.RelatedTo;
import org.springframework.data.neo4j.support.index.IndexType; @NodeEntity
public class WordEntity {
@GraphId Long id; // @Indexed(unique = true,indexType = IndexType.FULLTEXT, indexName = "wordName")
private String name; private String domain; private String dict; private String pos; @RelatedTo(type = "labeled")
Set<LabelEntity> labels = new HashSet<LabelEntity>(); public WordEntity(){ } public WordEntity(String name){
this.name = name;
} public Long getId() {
return id;
} public String getName() {
return name;
} public void setName(String name) {
this.name = name;
} public String getPos() {
return pos;
} public void setPos(String pos) {
this.pos = pos;
} public Set<LabelEntity> getLabels() {
return labels;
} public void setLabels(Set<LabelEntity> labels) {
this.labels = labels;
} public String getDict() {
return dict;
} public void setDict(String dict) {
this.dict = dict;
} public String getDomain() {
return domain;
} public void setDomain(String domain) {
this.domain = domain;
} @Override
public String toString() {
return "WordEntity [id=" + id + ", name=" + name + "]";
} }

3)repository

import java.util.List;

//import org.springframework.data.neo4j.annotation.Query;
//import org.springframework.data.neo4j.repository.GraphRepository;
//import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
//import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Repository; import com.bonc.knowledge.model.WordEntity; @RepositoryRestResource(collectionResourceRel = "word", path = "word")
@Repository
public interface WordRepository extends PagingAndSortingRepository<WordEntity, Long> { List<WordEntity> findByName(@Param("name") String name); }

spring boot + neo4j restful的更多相关文章

  1. 使用Spring boot开发RestFul 风格项目PUT/DELETE方法不起作用

    在使用Spring boot 开发restful 风格的项目,put.delete方法不起作用,解决办法. 实体类Student @Data public class Student { privat ...

  2. Spring Boot - Building RESTful Web Services

    Spring Boot Building RESTful Web Services https://www.tutorialspoint.com/spring_boot/spring_boot_bui ...

  3. Spring Boot2 系列教程(三十一)Spring Boot 构建 RESTful 风格应用

    RESTful ,到现在相信已经没人不知道这个东西了吧!关于 RESTful 的概念,我这里就不做过多介绍了,传统的 Struts 对 RESTful 支持不够友好 ,但是 SpringMVC 对于 ...

  4. Spring Boot构建 RESTful 风格应用

    Spring Boot构建 RESTful 风格应用 1.Spring Boot构建 RESTful 风格应用 1.1 实战 1.1.1 创建工程 1.1.2 构建实体类 1.1.4 查询定制 1.1 ...

  5. Spring Boot开发RESTful接⼝服务及单元测试

    Spring Boot开发RESTful接⼝服务及单元测试 常用注解解释说明: @Controller :修饰class,⽤来创建处理http请求的对象 @RestController :Spring ...

  6. 基于Spring Boot的RESTful API实践(一)

    1. RESTful简述    REST是一种设计风格,是一组约束条件及原则,而遵循REST风格的架构就称为RESTful架构,资源是RESTful的核心,一个好的RESTful架构,通过URL就能很 ...

  7. 用Kotlin写一个基于Spring Boot的RESTful服务

    Spring太复杂了,配置这个东西简直就是浪费生命.尤其在没有什么并发压力,随便搞一个RESTful服务 让整个业务跑起来先的情况下,更是么有必要纠结在一堆的XML配置上.显然这么想的人是很多的,于是 ...

  8. Spring Boot提供RESTful接口时的错误处理实践

    使用Spring Boot开发微服务的过程中,我们会使用别人提供的接口,也会设计接口给别人使用,这时候微服务应用之间的协作就需要有一定的规范. 基于rpc协议,我们一般有两种思路:(1)提供服务的应用 ...

  9. Spring Boot中Restful Api的异常统一处理

    我们在用Spring Boot去向前端提供Restful Api接口时,经常会遇到接口处理异常的情况,产生异常的可能原因是参数错误,空指针异常,SQL执行错误等等. 当发生这些异常时,Spring B ...

随机推荐

  1. -Swift.h not find

    亲测成功. 随便新建一个swift文件,xcode问是否生成xxx-Bridging-Header.h文件,点YES.再编译,问题解决. By default, the generated heade ...

  2. perl面向对象

    来源: http://www.cnblogs.com/itech/archive/2012/08/21/2649580.html Perl面向对象     首先让我们来看看有关 Perl 面向对象编程 ...

  3. sql求日期

    2.求以下日期SQL: 昨天 select convert(varchar(10),getdate() - 1,120) 明天 select convert(varchar(10),getdate() ...

  4. Sockets

    Sockets time limit per test 2 seconds memory limit per test 256 megabytes input standard input outpu ...

  5. Objective-C相关Category的收集

    Objective-C相关Category的收集 Categories是给你得不到源码的classes增加功能的一种方法.这个页面收集一些相关的Category,并且持续更新,你可以订阅关注.作者是F ...

  6. SQL Server触发器的禁用和启用

    禁用: ALTER TABLE trig_example DISABLE TRIGGER trig1 GO 恢复: ALTER TABLE trig_example ENABLE TRIGGER tr ...

  7. 学习笔记——门面模式Facade

    门面模式,其实在我们不经意间已经使用了此设计模式.当我们需要将两个子系统,合并对外提供一个大的接口时,我们使用的就是门面模式.对外,子系统的接口是不可见的,只有我们的门面在.

  8. psy & vr

    技术指标及应用法则:PSY和VR 一.PSY(Psychologial Line)   1. PSY的参数 2. PSY的应用法则 二.VR(Volume Ratio) 1. VR的参数 2. VR的 ...

  9. kill -QUIT <pid>

    On Solaris and Linux a thread dump is also printed if the J2SE process receives a QUIT signal. So ki ...

  10. cakephp , the subquery

    Cakephp 框架帮我们做了很多的工作,的确省了我们很多工作,提高了效率. 但是,碰到一些比较复杂的查询时,还是有些问题,官方的cookbook api 有说明一些详细的用法,但感觉还是不太够,有些 ...