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)主启动类

springboot+mybatis-plus+oracle项目搭建

 添加@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数据库

springboot+mybatis-plus+oracle项目搭建

 

5.测试结果

springboot+mybatis-plus+oracle项目搭建

 

上一篇:SpringBoot项目-使用外部Tomcat启动


下一篇:web前端开发怎样自学,html培训机构知乎