spring boot + neo4j restful
整整折腾了三天,终于把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的更多相关文章
- 使用Spring boot开发RestFul 风格项目PUT/DELETE方法不起作用
在使用Spring boot 开发restful 风格的项目,put.delete方法不起作用,解决办法. 实体类Student @Data public class Student { privat ...
- Spring Boot - Building RESTful Web Services
Spring Boot Building RESTful Web Services https://www.tutorialspoint.com/spring_boot/spring_boot_bui ...
- Spring Boot2 系列教程(三十一)Spring Boot 构建 RESTful 风格应用
RESTful ,到现在相信已经没人不知道这个东西了吧!关于 RESTful 的概念,我这里就不做过多介绍了,传统的 Struts 对 RESTful 支持不够友好 ,但是 SpringMVC 对于 ...
- Spring Boot构建 RESTful 风格应用
Spring Boot构建 RESTful 风格应用 1.Spring Boot构建 RESTful 风格应用 1.1 实战 1.1.1 创建工程 1.1.2 构建实体类 1.1.4 查询定制 1.1 ...
- Spring Boot开发RESTful接⼝服务及单元测试
Spring Boot开发RESTful接⼝服务及单元测试 常用注解解释说明: @Controller :修饰class,⽤来创建处理http请求的对象 @RestController :Spring ...
- 基于Spring Boot的RESTful API实践(一)
1. RESTful简述 REST是一种设计风格,是一组约束条件及原则,而遵循REST风格的架构就称为RESTful架构,资源是RESTful的核心,一个好的RESTful架构,通过URL就能很 ...
- 用Kotlin写一个基于Spring Boot的RESTful服务
Spring太复杂了,配置这个东西简直就是浪费生命.尤其在没有什么并发压力,随便搞一个RESTful服务 让整个业务跑起来先的情况下,更是么有必要纠结在一堆的XML配置上.显然这么想的人是很多的,于是 ...
- Spring Boot提供RESTful接口时的错误处理实践
使用Spring Boot开发微服务的过程中,我们会使用别人提供的接口,也会设计接口给别人使用,这时候微服务应用之间的协作就需要有一定的规范. 基于rpc协议,我们一般有两种思路:(1)提供服务的应用 ...
- Spring Boot中Restful Api的异常统一处理
我们在用Spring Boot去向前端提供Restful Api接口时,经常会遇到接口处理异常的情况,产生异常的可能原因是参数错误,空指针异常,SQL执行错误等等. 当发生这些异常时,Spring B ...
随机推荐
- 图解HTTP读书笔记--精简版
这本书重点讲了两点,分别是 HTTP的报文格式 HTTPS比HTTP优秀在哪里 接下来分部分讨论一下: 1. HTTP的报文格式 请求报文格式: 请求行 指明请求方法 请求路径 和协议 如 ...
- Ansible9:条件语句【转】
在有的时候play的结果依赖于变量.fact或者是前一个任务的执行结果,从而需要使用到条件语句. 一.when 有的时候在特定的主机需要跳过特定的步骤,例如在安装包的时候,需要指定主机的操作系统 ...
- MySQL慢日志查询全解析:从参数、配置到分析工具【转】
转自: MySQL慢日志查询全解析:从参数.配置到分析工具 - MySQL - DBAplus社群——围绕数据库.大数据.PaaS云,运维圈最专注围绕“数据”的学习交流和专业社群http://dbap ...
- 浅谈测试rhel7新功能时的感受及遇到的问题【转载】
半夜起来看世界杯,没啥激情,但是又怕错误意大利和英格兰的比赛,就看了rhel7 相关新功能的介绍. rhel7的下载地址: https://access.redhat.com/site/downloa ...
- 确定当前Python环境中的site-packages目录位置
引入“搜索路径”这个概念是因为在使用import语句时,当解释器遇到import语句,如果模块在当前的搜索路径就会被导入. 搜索路径是一个解释器会先进行搜索的所有目录的列表. 那么python如何添加 ...
- go mode
https://github.com/dominikh/go-mode.el http://blog.altoros.com/golang-part-1-main-concepts-and-proje ...
- socket小解
要理解socket,首先得理解TCP/IP协议族, TCP/IP (Transmission Control Protocol/Internet Protocol)传输控制协议/网间协议 定义: TC ...
- oracle10g遇到ORA-00257归档程序错误,在释放之前仅限于内部连接
一.简要介绍 首先数据库日志文件有两种: 联机日志文件和归档日志文件,联机日志文件会将之前的覆盖,不会做备份. 而归档日志文件会做备份,这样就造成了归档日志空间已满,解决方法: 如果真的是归档日志空间 ...
- robot framework -记录关键字
1.set value if (当条件满足时,进行变量赋值) 2.focus (将焦点定在制定的元素) 3.win close +title(关闭制定title) 4.get list items ...
- 动画——animation(2)
日常中,我们使用的动画来源有两个方面—— 第一个,自己去定义. 通过@keyframes去定义即可,格式如下: @keyframe animatename{ 0%{ //这里面写初始的对象的css样式 ...