Java教程

springboot+mybatis-plus+oracle项目搭建

本文主要是介绍springboot+mybatis-plus+oracle项目搭建,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

1.pom.xml导入依赖

<dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>com.oracle.database.jdbc</groupId>
            <artifactId>ojdbc8</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <!-- mybatis-plus-->
        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus</artifactId>
            <version>2.3</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/com.baomidou/mybatis-plus-boot-starter -->
        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
            <version>2.3</version>
        </dependency>
        <!-- mybatis-->
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis</artifactId>
            <version>3.5.6</version>
        </dependency>
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>2.1.4</version>
        </dependency>
        <!-- lombok-->
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.20</version>
        </dependency>
        <!--oracle字符集  https://mvnrepository.com/artifact/cn.easyproject/orai18n-->
        <dependency>
            <groupId>cn.easyproject</groupId>
            <artifactId>orai18n</artifactId>
            <version>12.1.0.2.0</version>
        </dependency>
    </dependencies>

2.application.properties文件配置

spring.datasource.username=root
spring.datasource.password=root
spring.datasource.url=jdbc:oracle:thin:@localhost:1521:orcl
spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver

3.代码编写

(1)mapper层

@Mapper
@Repository
public interface UserMapper extends BaseMapper<User> {
}

(2)pojo层

@AllArgsConstructor
@NoArgsConstructor
@TableName("tb_user")
@Data
public class User implements Serializable {
    private Integer user_id;
    private String user_name;
    private String user_pwd;
}

(3)主启动类

 添加@MapperScan注解,扫描包,放在@SpringBootApplication注解上面

(4)springboot测试类

@SpringBootTest
class MybatisPlusApplicationTests {

    @Autowired
    UserMapper userMapper;

    @Test
    void contextLoads() {
        List<User> users = userMapper.selectList(null);
        for (User user : users) {
            System.out.println(user);
        }
    }
    
}

4.oracle数据库

 

5.测试结果

 

这篇关于springboot+mybatis-plus+oracle项目搭建的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!