日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
mybatis配置oracle數(shù)據(jù)庫

MyBatis-Plus 配置 Oracle 數(shù)據(jù)庫的方法主要包括以下幾個(gè)步驟:

成都創(chuàng)新互聯(lián)公司主營韶關(guān)網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營網(wǎng)站建設(shè)方案,App定制開發(fā),韶關(guān)h5成都小程序開發(fā)搭建,韶關(guān)網(wǎng)站營銷推廣歡迎韶關(guān)等地區(qū)企業(yè)咨詢

1、引入依賴

2、配置數(shù)據(jù)源

3、配置 MyBatis-Plus

4、配置 Oracle 相關(guān)配置

1. 引入依賴

在項(xiàng)目的 pom.xml 文件中添加 MyBatis-Plus 和 Oracle 相關(guān)的依賴:


    
    
        com.baomidou
        mybatis-plus-boot-starter
        最新版本
    
    
    
        com.oracle.database.jdbc
        ojdbc8
        19.3.0.0
    

2. 配置數(shù)據(jù)源

在 application.yml 或 application.properties 文件中配置數(shù)據(jù)源信息:

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

3. 配置 MyBatis-Plus

在 MyBatis-Plus 的配置文件中,可以配置一些通用的屬性,例如駝峰命名轉(zhuǎn)換、自動(dòng)填充等。

@Configuration
@MapperScan("com.example.demo.mapper")
public class MybatisPlusConfig {
    @Bean
    public MybatisConfigurationCustomizer mybatisConfigurationCustomizer() {
        return new MybatisConfigurationCustomizer() {
            @Override
            public void customize(MybatisConfiguration configuration) {
                configuration.setMapUnderscoreToCamelCase(true);
                configuration.setUseGeneratedKeys(true);
                configuration.setDefaultExecutorType(ExecutorType.REUSE);
                configuration.setDefaultStatementTimeout(25000);
            }
        };
    }
}

4. 配置 Oracle 相關(guān)配置

在 MyBatis-Plus 的配置文件中,可以配置一些與 Oracle 相關(guān)的屬性,例如序列生成器、分頁插件等。

@Configuration
public class MybatisPlusOracleConfig {
    @Bean
    public PaginationInterceptor paginationInterceptor() {
        return new PaginationInterceptor();
    }
    @Bean
    public GlobalConfig globalConfig() {
        GlobalConfig config = new GlobalConfig();
        config.setSqlInjector(new OracleSqlInjector());
        return config;
    }
}

相關(guān)問題與解答:

1、如何在 MyBatis-Plus 中使用 Oracle 的序列作為主鍵生成策略?

答:在實(shí)體類的主鍵字段上添加 @TableId 注解,并設(shè)置 typeIdType.ASSIGN_ID,然后在 globalConfig 中配置 OracleSequenceIdGenerator。

@TableId(type = IdType.ASSIGN_ID)
private Long id;
@Bean
public GlobalConfig globalConfig() {
    GlobalConfig config = new GlobalConfig();
    config.setSqlInjector(new OracleSqlInjector());
    config.setIdType(IdType.ASSIGN_ID);
    config.setGlobalConfig(new GlobalConfig().getDbConfig().getTablePrefix());
    config.setIdentifierGenerator(new OracleSequenceIdGenerator());
    return config;
}

2、如何在 MyBatis-Plus 中配置 Oracle 的分頁插件?

答:在 MybatisPlusOracleConfig 類中添加一個(gè) PaginationInterceptor 的 Bean,并在 globalConfig 中配置分頁插件。

@Bean
public PaginationInterceptor paginationInterceptor() {
    return new PaginationInterceptor();
}
@Bean
public GlobalConfig globalConfig() {
    GlobalConfig config = new GlobalConfig();
    config.setSqlInjector(new OracleSqlInjector());
    config.setIdType(IdType.ASSIGN_ID);
    config.setGlobalConfig(new GlobalConfig().getDbConfig().getTablePrefix());
    config.setIdentifierGenerator(new OracleSequenceIdGenerator());
    config.setPagination(true);
    return config;
}

網(wǎng)站題目:mybatis配置oracle數(shù)據(jù)庫
網(wǎng)站網(wǎng)址:http://www.5511xx.com/article/cdigpis.html