zoukankan      html  css  js  c++  java
  • 心态炸了,我再写一个4.1.0版本的SND实例

    maven依赖

    <!-- Tests -->
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-test</artifactId>
    <version>4.2.5.RELEASE</version>
    <scope>test</scope>
    </dependency>

    <!--SDN-->
    <dependency>
    <groupId>org.springframework.data</groupId>
    <artifactId>spring-data-neo4j</artifactId>
    <version>4.1.0.RELEASE</version>
    </dependency>

    <!--Neo4j-->
    <dependency>
    <groupId>org.neo4j</groupId>
    <artifactId>neo4j-ogm-test</artifactId>
    <version>2.1.0</version>
    <scope>test</scope>
    </dependency>

    <dependency>
    <groupId>org.neo4j</groupId>
    <artifactId>neo4j-kernel</artifactId>
    <version>3.1.0</version>
    </dependency>

    <dependency>
    <groupId>org.neo4j.app</groupId>
    <artifactId>neo4j-server</artifactId>
    <version>3.1.0</version>
    </dependency>

    <dependency>
    <groupId>org.neo4j.test</groupId>
    <artifactId>neo4j-harness</artifactId>
    <version>3.1.0</version>
    <scope>test</scope>
    </dependency>

    <dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.12</version>
    <scope>test</scope>
    </dependency>

    domain model(com.shubo.neo4j.domain)

    @NodeEntity
    public class Person {
    @GraphId
    private Long nodeId;
    String name;
    String from;
    String hobbies;

    public Person(){
    }

    public Person(String name,String from, String hobbies){
    this.name = name;
    this.from = from;
    this.hobbies = hobbies;
    }

    }

    repository(com.shubo.neo4j.repositories)

    public interface PersonRepository extends GraphRepository<Person> {
    }

    configuration(ogm.repositories,SDN会自动扫描该文件,以及配置方法的声明和一个使用实例)

    @Configuration
    @EnableNeo4jRepositories(basePackages = "com.shubo.neo4j.repository")
    @EnableTransactionManagement
    @ComponentScan("com.shubo.neo4j")
    public class MyConfiguration extends Neo4jConfiguration{
    @Bean
    public SessionFactory getSessionFactory(){
    return new SessionFactory("com.shubo.neo4j.domain");
    }

    @Bean
    public Session getSession() throws Exception {
    return super.getSession();
    }
    }

    @RunWith(SpringJUnit4ClassRunner.class)
    @ContextConfiguration(classes = {MyConfiguration.class})
    public class Neo4jTest {

    @Autowired
    PersonRepository personRepository;

    @Test
    public void testCRUDPerson(){
    System.out.println(personRepository.getClass());
    Person person = new Person("Jerry","China","LOL");
    personRepository.save(person);
    System.out.println("保存成功");
    }
    }


  • 相关阅读:
    Java 学习笔记- classpath classpath*
    Java this关键字 学习笔记
    Java 基础 类加载器和双亲委派机制 学习笔记
    《Java语言实现快速幂取模》
    《2017年内蒙古自治区第十二届大学生程序设计-超级密码》
    《快速排序》
    《01-背包问题-点菜》
    微信小程序相关二、css介绍,菜单制作,表单相关,京东注册页面
    微信小程序相关一、模仿京东静态登录页面
    分别用js和css实现瀑布流
  • 原文地址:https://www.cnblogs.com/shirandedan/p/7199459.html
Copyright © 2011-2022 走看看