<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-neo4j</artifactId></dependency>
2.写yml
spring:data:neo4j:database: neo4j:uri: bolt://localhost:7687authentication:username: password:
3.写实体类
举个例子:
在neo4j中查询,点击表格查看数据结构
identity即id,labels标签,一般我们的实体类就是以他为基准
@Node("症状") @Data @NoArgsConstructor public class Symptom {@Id // 标识这是主键,对应Neo4j的内部id @GeneratedValueprivate Long identity;@Property("名称") // 对应properties中的"名称"属性private String name; }
dao层
public interface SymptomRepository extends Neo4jRepository<Symptom, Long> {@Query("MATCH (n:`症状`) RETURN n")List<Symptom> findAll();}
service层
@Service public class SymptomService {@AutowiredSymptomRepository symptomRepository;public List<Symptom>findAll(){List<Symptom> all = symptomRepository.findAll();return all;} }
controller层
@RestController @RequestMapping("/collect") public class CollectController {@AutowiredSymptomService service;@RequestMapping("/all")public Result getAll(){return Result.success(service.findAll());}}
Apipost测试结果