springBoot+mybatisPlus+Oracle+Junit4框架整合

springBoot+mybatisPlus+Oracle+Junit4整合

1.工程总结构目录
springBoot+mybatisPlus+Oracle+Junit4框架整合_第1张图片

2.maven依赖(pom.xml)

<dependencies>
        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starterartifactId>
            <version>2.1.4.RELEASEversion>
        dependency>

        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starter-webartifactId>
            <version>2.1.4.RELEASEversion>
        dependency>
       <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starter-testartifactId>
            <version>2.1.4.RELEASEversion>
        dependency>
        <dependency>
            <groupId>org.projectlombokgroupId>
            <artifactId>lombokartifactId>
            <version>1.18.10version>
        dependency>
        
        <dependency>
            <groupId>com.alibabagroupId>
            <artifactId>fastjsonartifactId>
            <version>1.2.48version>
        dependency>
        <dependency>
            <groupId>com.oracle.database.jdbcgroupId>
            <artifactId>ojdbc8artifactId>
            <version>12.2.0.1version>
        dependency>

        <dependency>
            <groupId>org.slf4jgroupId>
            <artifactId>slf4j-apiartifactId>
            <version>1.7.26version>
        dependency>
        <dependency>
            <groupId>org.slf4jgroupId>
            <artifactId>slf4j-log4j12artifactId>
            <version>1.7.26version>
        dependency>
        <dependency>
            <groupId>com.baomidougroupId>
            <artifactId>mybatis-plus-boot-starterartifactId>
            <version>3.0.5version>
        dependency>
        
        <dependency>
            <groupId>org.springframeworkgroupId>
            <artifactId>spring-testartifactId>
            <version>4.3.24.RELEASEversion>
        dependency>

        <dependency>
            <groupId>junitgroupId>
            <artifactId>junitartifactId>
            <version>4.13version>
        dependency>
        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-testartifactId>
            <version>2.1.4.RELEASEversion>
        dependency>

3.配置文件(AppApplication)

server:
  port: 80
spring:
  datasource:
    driver-class-name: oracle.jdbc.OracleDriver
    url: jdbc:oracle:thin:@192.168.8.222:1521:orcl
    username: data
    password: 123

4.创建entity实体类

package com.somj.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;

@Data
@TableName("ms_user")
public class MsUser {
    @TableField("user_id")
    private int userId;
    @TableField("user_name")
    private String userName;
    @TableField("mobile_phone")
    private String mobilePhone;
}

5.创建mapper接口

package com.somj.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.somj.entity.MsUser;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Repository;

@Repository
@Mapper
public interface MsUserMapper extends BaseMapper<MsUser> {
}

6.创建junit4测试类

package com.somj.test;

import com.somj.entity.MsUser;
import com.somj.mapper.MsUserMapper;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.List;


@SpringBootTest
//@SpringBootTest
@RunWith(SpringRunner.class)
public class MsUserTest {

    //@Resource(mappedName = "msUserMapper")
    @Autowired(required=true)
    private MsUserMapper msUserMapper;

    @Test
    public void test1(){
        List<MsUser> blUserLists = msUserMapper.selectList(null);
        System.out.println(blUserLists);
    }
}

springBoot+mybatisPlus+Oracle+Junit4框架整合_第2张图片

7.创建controller

package com.somj.controller;

import com.somj.entity.MsUser;
import com.somj.mapper.MsUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


import java.util.List;

@RestController
public class ControllerTest {

    @Autowired
    private MsUserMapper msUserMapper;

    @RequestMapping("/test")
    public String getNameById(){
        List<MsUser> msUsers = msUserMapper.selectList(null);
        return msUsers.toString();
    }
}

springBoot+mybatisPlus+Oracle+Junit4框架整合_第3张图片

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