springBoot集成neo4j实现查询节点

springBoot+neo4j的文件目录
springBoot集成neo4j实现查询节点_第1张图片

  • 导入pom.xml依赖

          org.springframework.data
          spring-data-neo4j
          5.1.8.RELEASE


  • 实现简单的查询接口

public interface Neo4jService {

    public JSONObject searchNode() throws  Exception;

}
@Service
@Slf4j
public class Neo4jServiceImpl implements Neo4jService {

    private String uri="bolt://localhost:7687";  //neo4j端口
    private String username="neo4j";    //用户名
    private String password="111111";   //密码

    public Driver createDrive(){

        return GraphDatabase.driver( uri, AuthTokens.basic(username, password) );
    }
    
    @Override
    public JSONObject searchNode() {
        Driver driver = createDrive();
        JSONObject js1=new JSONObject();
        try(Session session = driver.session()){
          String neoSql="MATCH (n:TBL) RETURN n.incrementCount as incrementCount,n.Dbname as Dbname;";
          StatementResult result = session.run(neoSql);

            while(result.hasNext()) {

                Record record = result.next();

                List keys1 = record.keys();
                for (int i=0;i

@RestController
public class Neo4jController {

    @Autowired
    private Neo4jService neo4jService;
    @RequestMapping(value = "/search")
    public String searchNode()throws Exception{
          JSONObject jsonObject = neo4jService.searchNode();
          return jsonObject.toString();
      }
    }

你可能感兴趣的:(图数据库)