首页 > 作文

springboot neo4j的配置代码

更新时间:2023-04-04 09:00:18 阅读: 评论:0

neo4j是一个图形数据库,有一个做关系图谱的需求里面需要使用到图形数据库。

w3c教程:https://www.w3cschool.cn/neo4j/

中文版的数据库可以通过image属性显示图片,官网的动画效果是通过3d.js实现的;

pom导入配置

<dependency>            <groupid>org.springframework.boot</groupid>            <artifactid>spring-boot-starter-data-neo4j</artifactid>        </dependency> <dependency>            <groupid>org.neo4j</groupid>            <artifactid>neo4j-ogm-http-driver</artifactid>            <version>3.1.4</version>        </dependency>

配置数据库:

#neo4jspring.data.neo4j.urname=neo4jspring.data.neo4j.password=123spring.data.neo4j.uri=http://192.168.100.106:7474package com.koala.console.configuration;import org.neo4j.ogm.ssion.ssionfactory;import org.springframework.beans.factory.annotation.value;import org.springframework.context.annotation.bean;import org.springframework.context.annotation.configuration;import org.springframework.data.neo4j.repository.config.enableneo4jrepositories;import org.spri关汉卿ngframework.data.neo4j.transaction.neo4jtransactionmanager;import org.springframework.transaction.annotation.enabletransactionmanagement;@configuration@enableneo4jrepositories(bapackages = "com.koala.console.repository.neo4j")@enabletransactionmanagementpublic class neo4jconfig {    @value("${bloturi}")    private string uri;    @value("${spring.data.neo4j.uri}")    private string databaurl;    @value("${spring.data.neo4j.urname}")    private string urname;    @value("${spring.data.neo4j.password}")    private string password;    @bean    public ssionfactory ssionfactory() {        org.neo4j.ogm.config.configuration configuration = new org.neo4j.ogm.config.configuration.builder()                .uri(databaurl)                .credentials(urname, password)                .build();        return new ssionfactory(configuration, "com.koala.console.model.neo4j");    }    @bean    public neo4jtransactionmanager transactionmanager() {        return new neo4jtransactionmanager(ssionfactory());    }}

使用neo4j:

neo4j基本由两部分组成,节点和关系,关系用来指示两个节点的方向和关联属性:

节点bean:

package com.koala.console.model.neo4j;import com.alibaba.fastjson.annotation.jsonfield;import com.fastleaveerxml.jackson.annotation.jsonignore;import com.google.common.collect.lists;import lombok.data;import org.neo4j.ogm.annotation.*;import org.springframework.web.multipart.multipartfile;import java.util.list;@data@nodeentitypublic class facenode {    public facenode() {    }    public facenode(string name) {        this.objid = name;    }    @id    @generatedvalue    private long id;    /**     * objid     */    private string objid;    @jsonfield(rialize = fal)    @jsonignore    @transient    private string startname;    @jsonfield(rialize = fal)    @jsonignore    @transient    private string endname;    @transient    private integer pathnum;    @transient    private string intimacy;    @property(name = "scenes")    private string scenes;    @property(name = "image")    private string symbol;    @transient    private integer[] symbolsize = {60,60};    @jsonfield(rialize = fal)    @transient    private multipartfile faceimg;    @jsonfield(rialize = fal)    @transient    private string starttime;    @jsonfield(rialize = fal)    @transient    private string endtime;    @relationship(type = "relation")    private list<facenodepro> facenodepros = lists.newarraylist();    private list<facenode>  children = lists.newarraylist();    public void addendnode(facenode endnode, string title) {        facenodepro pro = new facenodepro(title, this, endnode);        this.facenodepros.add(pro);    }    public void addstartnode(facenode startnode, string title) {        facenodepro pro = new facenodepro(title, startnode, this);        this.facenodepros.add(pro);    }    public long getid() {        return id;    }    public void tid(long id) {        this.id = id;    }    public string getobjid() {        return objid;    }    public void tobjid(string objid) {        this.objid = objid;    }    public string getsymbol() {        return symbol;    }    public void tsymbol(string symbol) {        this.symbol = symbol;    }    public list<facenodepro> getfacenodepros() {        return facenodepros;    }    public void tfacenodepros(list<facenodepro> facenodepros) {        this.facenodepros = facenodepros;    }    public string getstartname() {        return startname;    }    public void tstartname(string startname) {        this.startname = startname;    }    public string getendname() {        return endname;    }    public void tendname(string endname) {        this.endname = endname;    }    pu超市店长blic multipartfile getfaceimg() {        return faceimg;    }    public void tfaceimg(multipartfile faceimg) {        this.faceimg = faceimg;    }    public string getstarttime() {        return starttime;    }    public void tstarttime(string starttime) {        this.starttime = starttime;    }    public string getendtime() {        return endtime;    }    public void tendtime(string endtime) {        this.endtime = endtime;    }    public string getscenes() {        return scenes;    }    public void tscenes(string scenes) {        this.scenes = scenes;    }}

关系bean:

package com.koala.console.model.neo4j;import com.fasterxml.jackson.annotation.jsonbackreference;import org.neo4j.ogm.annotation.*;@relationshipentity(type = "relation")public class facenodepro {    public facenodepro() {    }    public facenodepro(string intimacy, facenode startnode, facenode endnode) {        this.intimacy = intimacy;        this.startnode = startnode;        this.endnode = endnode;    }    @id    @generatedvalue    private long nodeproid;    /**     * 亲密度     */    @property    private string intimacy;    @jsonbackreference    @startnode    private facenode startnode;    @endnode    private facenode endnode;    public long getnodeproid() {        return nodeproid;    }    public void tnodeproid(long nodeproid) {        this.nodeproid = nodeproid;    }    public string getintimacy() {        return intimacy;    }    public void tintimacy(string intimacy) {        this.intimacy = intimacy;    }    public facenode getstartnode() {        return startnode;    }    public void tstartnode(facenode startnode) {        this.startnode = startnode;    }    public facenode getendnode() {        return endnode;    }    public void tendnode(facenode endnode) {        this.endnode = endnode;    }}

repository实现:

@repositorypublic interface facenoderepository extends neo4jrepository<facenode, long> {    facenode findbyobjid(@param("objid") string objid);    /**     * 查询节点node指定层级的图     *     * @param     * @return     */    @query(value = "match n=(:facenode{objid:{objid}})-[*..6]->() return n")    list<facenode> findbyhierarchical(@param("objid") string objid);}

剩下的使用都是很简单的事情。

我收集了一些会使用到的语句:

查询节点node所有的关系match(node{name:'5c26219bd3e2dca5322110bb'})-[:played_in]->(yf)return node,yf查询节点node的2层关系图match n=(:node{name:"5c262177d3e2dca5322110b3"})-[*..1]-() return n两个陌生人之间的所有最短认识路径match n = allshortestpaths((小讯:朋友圈{姓名:"小讯"})-[*..6]-(小菲:朋友圈{姓名:"小菲"})) return n查询节点node指向的所有节点match (:node { name: '5c262137d3e2dca5322110a7' })-->(movie)return movie;查询标签node所有节点match(n)--(m:node)return n;批量创建node节点的朋友圈match (node:node {name:"4j2ap"})foreach (name in ["johan","rajesh","anna","julia","andrew"] |create (node)-[:friend]->(:person {name:name}))查询两个节点有向关系条数match (:facenode{name:"gong"})-[r:played_in]->(:facenode{name:"eza2e"})return count(r)

参考:

转载自:/d/file/titlepic/87092034br /> 版权声明:本文为博主原创文章,遵循cc 4.0分数除法应用题练习题 by-sa版权协议,转载请附上原文出处链接和本声明。

本文链接:https://blog.csdn.net/sinat_21184471我的母亲作文600字初中/article/details/87092034

到此这篇关于springbootneo4j的文章就介绍到这了,更多相关springbootneo4j内容请搜索www.887551.com以前的文章或继续浏览下面的相关文章希望大家以后多多支持www.887551.com!

本文发布于:2023-04-04 09:00:14,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/zuowen/ec8374c6e10fbec388a48c55721ea83f.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

本文word下载地址:springboot neo4j的配置代码.doc

本文 PDF 下载地址:springboot neo4j的配置代码.pdf

标签:节点   关系   数据库   朋友圈
相关文章
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图