springboot整合neo4j

springboot整合neo4j 执行指令

之前上网搜索配置都很凌乱,于是在 springboot neo4j文档 中摸索了下。
- pom配置

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-neo4j</artifactId>
        </dependency>
        <!-- add this dependency if you want to use the HTTP driver -->
        <dependency>
            <groupId>org.neo4j</groupId>
            <artifactId>neo4j-ogm-http-driver</artifactId>
            <version>3.0.1</version>
        </dependency>
  • application.properties
# 写入自己neo4j配置
spring.data.neo4j.uri=http://fp-bd13:7474
spring.data.neo4j.username=neo4j
spring.data.neo4j.password=admin
  • 实体Po
@Data //lombok注解
@NodeEntity
@ToString
public class Table {
    @Id
    @GeneratedValue
    private Long id;
    @Property
    private String name;
    @Property
    private String desc;
    @Property
    private String fields;
}
  • Dao

继承 Neo4jRepository 接口

@Repository
public interface TableDao extends Neo4jRepository<Table,Long> {
}
  • Service

注入Dao,如果注入neo4j的SessionFactory获取session可以用来执行cql命令。

@RestController
@RequestMapping("/v1/table")
public class TableService {

    @Autowired
    private SessionFactory sessionFactory;

    @Autowired
    TableDao tableDao;

    @RequestMapping("/create")
    public void create(@RequestBody Table table) {
        tableDao.save(table);
    }

    @RequestMapping("/executeCQL")
    public void executeCQL(String cypher){
        // cypher = "match (n: Table} ) delete n"
        sessionFactory.openSession().query(cypher,new HashMap<>());
    }
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值