SpringBoot 工程目录 整合mybatis-neo4j(注解类型)-增删改查

工程结构

├─java
│  └─com
│      └─claroja
│          │  App.java
│          │
│          ├─controller
│          │      Neo4jController.java
│          │
│          ├─dao
│          │      UserMapper.java
│          │
│          └─model
│                  User.java
│
└─resources
        application.yml

resources

resources/application.yml

spring:
  datasource:
    driver-class-name: org.neo4j.jdbc.http.HttpDriver
    url: jdbc:neo4j:http://192.168.2.222:7474
    username: neo4j
    password: 123456

java.com.claroja

java/com/claroja/App.java

package com.claroja;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
@MapperScan(basePackages = "com.claroja.dao") //开启注解
public class App {
    public static void main(String[] args) {
        SpringApplication.run(App.class, args);
    }
}

java/com/claroja/controller/Neo4jController.java

package com.claroja.controller;

import com.claroja.dao.UserMapper;
import com.claroja.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


@Controller
@CrossOrigin
public class Neo4jController {

    @Autowired
    private UserMapper userMapper;

    @RequestMapping("/set")
    @ResponseBody
    public void setEntity(@RequestBody User user){
        System.out.println(user);
        userMapper.setEntity(user);
    }
    @RequestMapping("/get")
    @ResponseBody
    public User getEntity(@RequestBody User user){
        System.out.println(user);
        return userMapper.getEntity(user);
    }
    @RequestMapping("/del")
    @ResponseBody
    public void delEntity(@RequestBody User user){
        System.out.println(user);
        userMapper.delEntity(user);
    }
    @RequestMapping("/update")
    @ResponseBody
    public void updateEntity(@RequestBody User user){
        System.out.println(user);
        userMapper.updateEntity(user);
    }
}

java/com/claroja/dao/UserMapper.java

package com.claroja.dao;

import com.claroja.model.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface UserMapper {
    @Insert("create(n${label}{name:#{name}})")
    public void setEntity(User user);

    @Select("match(n${label}) where n.name = #{name} return labels(n) as label, n.name as name")
    public User getEntity(User user);

    @Insert("match(n${label}) where n.name = #{name} delete n")
    public void delEntity(User user);

    @Update("match(n${label}) where n.name = #{name} set n.gender = #{gender}")
    public void updateEntity(User user);
}


java/com/claroja/model/User.java

package com.claroja.model;

public class User {

    private String label;
    private String name;
    private String gender;

    public String getLabel() {
        return label;
    }

    public void setLabel(String label) {
        this.label = label;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
    public String setGender() {
        return name;
    }

    public void getGender(String name) {
        this.name = name;
    }
}


POM

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.4.2</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.claroja</groupId>
    <artifactId>springboot-mybatis</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>springboot-mybatis</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <java.version>1.8</java.version>
    </properties>
    <dependencies>
        <dependency><!--web依赖-->
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency><!--热启动依赖-->
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
        </dependency>
        <dependency><!--测试依赖-->
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency><!--mybatis依赖-->
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>2.1.3</version>
        </dependency>
        <dependency><!--neo4j驱动-->
            <groupId>org.neo4j</groupId>
            <artifactId>neo4j-jdbc-driver</artifactId>
            <version>4.0.1</version>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值