Neo4j的电影例如返回畸形的JSON
我试图建立在https://neo4j.com/developer/example-project/Neo4j的电影例如返回畸形的JSON
链接发现代码中的春数据的Neo4j 4部 Neo4j的电影的例子是在https://github.com/neo4j-examples/movies-java-spring-data-neo4j-4
我把一切都运行起来本地。三个组件中的两个正在工作,电影列表和背景图。不工作的是在右侧显示个人电影。
此信息被填充开始在下面的代码
的index.html(开始于线82):
<script type="text/javascript"> $(function() {
function showMovie(title) {
$.get("/movies/search/findByTitle?title=" + encodeURIComponent(title), // todo fix paramter in SDN
function (data) {
if (!data) return; // || !data["_embedded"].movies) return;
var movie = data; // ["_embedded"].movies[0];
$("#title").text(movie.title);
...
});
}, "json");
return false;
}
...
</javascript>
功能,function (data)
不被调用。
要http://localhost:8080/movies/search/findByTitle?title=The%20Matrix%20Reloaded
被返回以下畸形的JSON:
{ "title" : "The Matrix Reloaded",
"released" : 2003,
"tagline" : "Free your mind",
"roles" : [ {
"roles" : [ "Morpheus" ],
"person" : {
"name" : "Laurence Fishburne",
"born" : 1961
},
"movie" : { : 9
}
}, {
"roles" : [ "Agent Smith" ],
"person" : {
"name" : "Hugo Weaving",
"born" : 1960
},
"movie" : { : 9
}
}, {
"roles" : [ "Trinity" ],
"person" : {
"name" : "Carrie-Anne Moss",
"born" : 1967
},
"movie" : { : 9
}
}, {
"roles" : [ "Neo" ],
"person" : {
"name" : "Keanu Reeves",
"born" : 1964
},
"movie" : { : 9
}
} ],
"_links" : {
"self" : {
"href" : "http://localhost:8080/movies/9"
},
"movie" : {
"href" : "http://localhost:8080/movies/9"
}
}
}
的ID是不正确填充。我试图运行这个例子开始学习spring-boot和neo4j,我不确定代码为什么没有返回正确的数据结构?
没有为Neo4j的查询日志条目:
MATCH (n:`Movie`) WHERE n.`title` = { `title_0` } WITH n MATCH p=(n)-[*0..1]-(m) RETURN p, ID(n) with params {title_0=The Matrix Reloaded}
我跑,在Neo4j的控制台,看着输出的文本:
╒══════════════════════════════╤═══════╕ │"p" │"ID(n)"│
╞══════════════════════════════╪═══════╡
│[] │"9" │
├──────────────────────────────┼───────┤
│[{"tagline":"Free your mind","│"9" │
│title":"The Matrix Reloaded","│ │
│released":"2003"},{"roles":["A│ │
│gent Smith"]},{"born":"1960","│ │
│name":"Hugo Weaving"}] │ │
├──────────────────────────────┼───────┤
│[{"tagline":"Free your mind","│"9" │
│title":"The Matrix Reloaded","│ │
│released":"2003"},{"roles":["M│ │
│orpheus"]},{"born":"1961","nam│ │
│e":"Laurence Fishburne"}] │ │
├──────────────────────────────┼───────┤
│[{"tagline":"Free your mind","│"9" │
│title":"The Matrix Reloaded","│ │
│released":"2003"},{"roles":["T│ │
│rinity"]},{"born":"1967","name│ │
│":"Carrie-Anne Moss"}] │ │
├──────────────────────────────┼───────┤
│[{"tagline":"Free your mind","│"9" │
│title":"The Matrix Reloaded","│ │
│released":"2003"},{"roles":["N│ │
│eo"]},{"born":"1964","name":"K│ │
│eanu Reeves"}] │ │
└──────────────────────────────┴───────┘
它看起来像问题是与此额外的ID(n)列。我不知道它为什么被添加,或者如何让它不被添加。唯一的代码,我可以看到这将产生暗号代码为MovieRepository.java
Movie findByTitle(@Param("title") String title);
这是一个版本的问题,还是其他什么东西?我怎样才能得到它不返回ID(n)列,或返回一个正确的ID:9结构?
回答:
我能够得到一个不同的例子,具有相同的结构,工作: https://github.com/springframeworkguru/spring-boot-neo4j-example然后修改它做我原来的例子试图做。然后,我可以比较两个项目之间的差异,将差异应用于原始项目并使其行为正确。 以下是所有代码的差异,使其正常工作:
的index.html(线105)评论脱节,没有必要
(105) //data = data["_embedded"].movies;
MovieService.java增加文件
public Movie getByTitle (String title){ return movieRepository.findByTitle (title); } public Collection<Movie> getByTitleContaining(String title) {
return movieRepository.findByTitleContaining (title);
}
MovieController。java的添加到文件
@RequestMapping("/movies/search/findByTitle") public Movie findByTitle(@RequestParam String title){
return movieService.getByTitle(title);
}
@RequestMapping("/movies/search/findByTitleContaining")
public Collection<Movie> findByTitleContaining(@RequestParam String title){
return movieService.getByTitleContaining(title);
}
MovieRepository.java(9号线和15)删除或注释掉
(9) //import org.springframework.data.rest.core.annotation.RepositoryRestResource; ...
(15) //@RepositoryRestResource(collectionResourceRel = "movies", path = "movies")
的pom.xml的可读性,我把整个文件在这里
<?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.neo4j.examples</groupId>
<artifactId>sdn4-movies</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>SDN4 University</name>
<description>Demo web project for Spring Boot using Spring Data Neo4j</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository --> <!-- added -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-neo4j</artifactId>
<!--<version>4.2.0.RELEASE</version>-->
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
<!--<artifactId>spring-boot-starter-data-neo4j</artifactId>-->
</dependency>
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-ogm-bolt-driver</artifactId>
<version>2.1.1</version>
</dependency>
<!--<dependency>-->
<!--<groupId>org.springframework.boot</groupId>-->
<!--<artifactId>spring-boot-starter-data-rest</artifactId>-->
<!--</dependency>-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- For some reason newer versions of jackson cause errors with -->
<!-- serialisation of nested objects in graph -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.8.0</version>
<!--<version>2.5.5</version>-->
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.8.6</version>
<!--<version>2.5.5</version>-->
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.8.6</version>
<!--<version>2.5.5</version>-->
</dependency>
<!-- ========================================== -->
<!-- For use in testing -->
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-ogm-embedded-driver</artifactId>
<version>2.1.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j</artifactId>
<version>3.1.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
回答:
此问题已于今天修复为:https://github.com/neo4j-examples/movies-java-spring-data-neo4j-4。
您不必更改任何代码。它会工作。
请注意,目前这需要使用SDN 4.2.2 SNAPSHOT版本。一旦Boot和Spring Data发布他们的下一个服务版本,我们将更新项目以删除它们。
以上是 Neo4j的电影例如返回畸形的JSON 的全部内容, 来源链接: utcz.com/qa/266271.html