Skip to content

Latest commit

 

History

History
63 lines (48 loc) · 1.51 KB

File metadata and controls

63 lines (48 loc) · 1.51 KB

springboot-db-neo4j

依赖引入

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-neo4j</artifactId>
        </dependency>

简单示例

@Data
@NodeEntity
public class Person implements Serializable {

    @Id
    @GeneratedValue
    private Long id;
    private String name;
}

public interface PersonRepository extends Neo4jRepository<Person, Long> {

    List<Person> findByName(String name);
}

测试类

@SpringBootTest
public class PersonRepositoryTests {

    @Resource
    private PersonRepository personRepository;

    @Test
    void save() {
        Person person = new Person();
        person.setId(1L);
        person.setName("lisi");
        personRepository.save(person);
    }

    @Test
    void findAll() {
        List<Person> all = (List<Person>)personRepository.findAll();
        System.out.println(all);
    }
}