SpringBoot+MyBatisPlus操作Oracle数据库

1.导入依赖

        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
            <version>3.4.2</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/com.oracle.database.jdbc/ojdbc8 -->
        <dependency>
            <groupId>com.oracle.database.jdbc</groupId>
            <artifactId>ojdbc8</artifactId>
            <version>12.2.0.1</version>
        </dependency>

2.编辑application.properties配置文件

spring.datasource.driver-class-name=oracle.jdbc.OracleDriver
spring.datasource.url=jdbc:oracle:thin:@127.0.0.1:1521/服务名
spring.datasource.username=xiaoming
spring.datasource.password=123456

工程目录结构:
SpringBoot+MyBatisPlus操作Oracle数据库_第1张图片

3.在启动类加上注解

package com.example.demo1;

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

@SpringBootApplication
@MapperScan("com.example.demo1.mapper")
public class Demo1Application {
    public static void main(String[] args) {
        SpringApplication.run(Demo1Application.class, args);
    }
}

4.编辑WarnRegionWhiteService接口

package com.example.demo1.service;

import com.baomidou.mybatisplus.extension.service.IService;
import com.example.demo1.entity.WarnRegionWhite;

import java.util.List;

public interface WarnRegionWhiteService extends IService<WarnRegionWhite> {
    List<WarnRegionWhite> selectAll();
}

5.编辑WarnRegionWhiteServiceImpl实现类

package com.example.demo1.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.demo1.entity.WarnRegionWhite;
import com.example.demo1.mapper.WarnRegionWhiteMapper;
import com.example.demo1.service.WarnRegionWhiteService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class WarnRegionWhiteServiceImpl extends ServiceImpl<WarnRegionWhiteMapper,WarnRegionWhite> implements WarnRegionWhiteService {
    @Override
    public List<WarnRegionWhite> selectAll() {
        QueryWrapper<WarnRegionWhite> qw = new QueryWrapper<>();
        qw.eq("id",4960);
        List<WarnRegionWhite> warnRegionWhiteList = baseMapper.selectList(qw);
        return warnRegionWhiteList;
    }
}

6.编辑WarnRegionWhiteMapper接口

package com.example.demo1.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.demo1.entity.WarnRegionWhite;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Repository;

@Repository
@Mapper
public interface WarnRegionWhiteMapper extends BaseMapper<WarnRegionWhite> {

}

7.编辑WarnRegionWhite实体类

package com.example.demo1.entity;

import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.io.Serializable;

@Data
@TableName("WORK.WARN_REGION_WHITE")
public class WarnRegionWhite implements Serializable {
    //成员属性
}

8.编辑Controller类

package com.example.demo1.controller;

import com.example.demo1.entity.WarnRegionWhite;
import com.example.demo1.service.WarnRegionWhiteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class TestController {
    @Autowired
    WarnRegionWhiteService warnRegionWhiteService;
    @GetMapping("/getOne")
    public List<WarnRegionWhite> getOne(){
        return warnRegionWhiteService.selectAll();
    }
}

9.打开浏览器

在地址栏输入http://127.0.0.1:8080/getOne 即可请求

你可能感兴趣的:(数据库,oracle,java,spring,boot)