春ブーツ:Boot2.0バージョンのNeo4jを統合

前に導入されたのNeo4jブート1.5バージョン統合、ブーツのNeo4jが大きく2.0上方に変化しました。
シーンや映画関係

ブート2.0の主な変更

  1. Boot2.0でGraphRepositoryはサポート、およびNeo4jRepositoryに調整されません。
    調整するfindByIdとdeleteById対応します。
  2. @GraphIdは@Id @GeneratedValueを変更する必要性をサポートしていません。
  3. ボルトに調整リンク://192.168.1.8:7687

デモ

  1. POMファイル
    ブートのバージョンを調整します
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.0.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
  1. application.yml設定
spring:
  data:
    neo4j:
      uri: bolt://192.168.1.8:7687
      username: neo4j
      password: 123456
  1. クラスモデルに調整
    Personクラス
package com.github.davidji80.springboot.neo4j.model;

import org.neo4j.ogm.annotation.*;

@NodeEntity(label = "Person")
public class Person {
    @Id
    @GeneratedValue
    private Long nodeId;

    @Property(name = "name")
    private String name;

    @Property(name = "born")
    private int born;

    public Long getNodeId() {
        return nodeId;
    }

    public void setNodeId(Long nodeId) {
        this.nodeId = nodeId;
    }


    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getBorn() {
        return born;
    }

    public void setBorn(int born) {
        this.born = born;
    }
}
  1. DAOに調整
    PersonRepository
package com.github.davidji80.springboot.neo4j.dao;

import com.github.davidji80.springboot.neo4j.model.Person;
import org.springframework.data.neo4j.repository.Neo4jRepository;

public interface PersonRepository extends Neo4jRepository<Person, Long> {
}
  1. サービス調整層
package com.github.davidji80.springboot.neo4j.service.impl;

import com.github.davidji80.springboot.neo4j.dao.ActedInRepository;
import com.github.davidji80.springboot.neo4j.dao.DirectedRepository;
import com.github.davidji80.springboot.neo4j.dao.MovieRepository;
import com.github.davidji80.springboot.neo4j.dao.PersonRepository;
import com.github.davidji80.springboot.neo4j.model.ActedIn;
import com.github.davidji80.springboot.neo4j.model.Directed;
import com.github.davidji80.springboot.neo4j.model.Movie;
import com.github.davidji80.springboot.neo4j.model.Person;
import com.github.davidji80.springboot.neo4j.service.MovieServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Optional;

@Service
public class MovieServiceImpl implements MovieServer {

    @Autowired
    private PersonRepository personRepository;
    @Autowired
    private MovieRepository movieRepository;
    @Autowired
    private DirectedRepository directedRepository;
    @Autowired
    private ActedInRepository actedInRepository;

    @Override
    public Person addPerson(Person person){
        return personRepository.save(person);
    }
    @Override
    public Person findOnePerson(long id){
        return personRepository.findById(id).get();
    }
    @Override
    public void deleteOnePerson(long id){
        personRepository.deleteById(id);
    }
    @Override
    public Movie addMovie(Movie movie){
        return movieRepository.save(movie);
    }
    @Override
    public Movie findOneMovie(long id){
        return movieRepository.findById(id).get();
    }
    @Override
    public Directed directed(Directed directed){
        return directedRepository.save(directed);
    }
    @Override
    public ActedIn actedIn(ActedIn actedIn) {
        return actedInRepository.save(actedIn);
    }
}

コード

https://github.com/DavidJi80/springboot
v0.8.1

参考
https://blog.csdn.net/d597180714/article/details/81079848
https://www.cnblogs.com/zhangboyu/p/7580262.html

オリジナル住所ます。https://www.jianshu.com/p/1aeeefb4fc7a

おすすめ

転載: www.cnblogs.com/jpfss/p/11232218.html