欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

mybatis自動建表的實現(xiàn)方法

 更新時間:2020年11月02日 14:42:00   作者:深藍(lán)格調(diào)_  
這篇文章主要介紹了mybatis自動建表的實現(xiàn)方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

1.添加ACTable依賴

   <!--mybatis-plus自動建表-->
    <dependency>
      <groupId>com.gitee.sunchenbin.mybatis.actable</groupId>
      <artifactId>mybatis-enhance-actable</artifactId>
      <version>1.1.1.RELEASE</version>
    </dependency>

2.配置(在此需要注意配置的路徑部分需要改成自己項目路徑)

   <!--mybatis-plus自動建表-->
    <dependency>
      <groupId>com.gitee.sunchenbin.mybatis.actable</groupId>
      <artifactId>mybatis-enhance-actable</artifactId>
      <version>1.1.1.RELEASE</version>
    </dependency>

3.添加配置類

package com.jpxx.clsh.autoconfig;

import com.alibaba.druid.pool.DruidDataSource;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.beans.factory.config.PropertiesFactoryBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;

/**
 * @ClassName TestConfig
 * @Description
 * @Author Administrator
 * @Date 2020/11/2 0002 11:30
 * @Version 1.0
 */
@Configuration
@ComponentScan(basePackages = {"com.gitee.sunchenbin.mybatis.actable.manager.*"})
public class DataSourceConfig{

  //此處的路徑按照yml或properties文件路徑
  @Value("${jpxx.datasource.druid.driverClassName}")
  private String driver;

  @Value("${jpxx.datasource.druid.url}")
  private String url;

  @Value("${jpxx.datasource.druid.username}")
  private String username;

  @Value("${jpxx.datasource.druid.password}")
  private String password;

  @Bean
  public PropertiesFactoryBean configProperties() throws Exception{
    PropertiesFactoryBean propertiesFactoryBean = new PropertiesFactoryBean();
    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    propertiesFactoryBean.setLocations(resolver.getResources("classpath*:application.yml"));
    return propertiesFactoryBean;
  }

  @Bean
  public DruidDataSource dataSource() {
    DruidDataSource dataSource = new DruidDataSource();
    dataSource.setDriverClassName(driver);
    dataSource.setUrl(url);
    dataSource.setUsername(username);
    dataSource.setPassword(password);
    dataSource.setMaxActive(30);
    dataSource.setInitialSize(10);
    dataSource.setValidationQuery("SELECT 1");
    dataSource.setTestOnBorrow(true);
    return dataSource;
  }

  @Bean
  public DataSourceTransactionManager dataSourceTransactionManager() {
    DataSourceTransactionManager dataSourceTransactionManager = new DataSourceTransactionManager();
    dataSourceTransactionManager.setDataSource(dataSource());
    return dataSourceTransactionManager;
  }

  @Bean
  public SqlSessionFactoryBean sqlSessionFactory() throws Exception{
    SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
    sqlSessionFactoryBean.setDataSource(dataSource());
    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    sqlSessionFactoryBean.setMapperLocations(resolver.getResources("classpath*:com/gitee/sunchenbin/mybatis/actable/mapping/*/*.xml"));
    sqlSessionFactoryBean.setTypeAliasesPackage("com.jpxx.clsh.entity.*");
    return sqlSessionFactoryBean;
  }

}
package com.jpxx.clsh.autoconfig;

/**
 * @ClassName MyBatisMapperScannerConfig
 * @Description
 * @Author Administrator
 * @Date 2020/11/2 0002 10:15
 * @Version 1.0
 */
import org.mybatis.spring.mapper.MapperScannerConfigurer;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@AutoConfigureAfter(DataSourceConfig.class)
public class MyBatisMapperScannerConfig {

  @Bean
  public MapperScannerConfigurer mapperScannerConfigurer() throws Exception{
    MapperScannerConfigurer mapperScannerConfigurer = new MapperScannerConfigurer();
    mapperScannerConfigurer.setBasePackage("com.jpxx.clsh.dao.*;com.gitee.sunchenbin.mybatis.actable.dao.*");
    mapperScannerConfigurer.setSqlSessionFactoryBeanName("sqlSessionFactory");
    return mapperScannerConfigurer;
  }

}

4.實體類

package com.jpxx.clsh.entity;

import com.gitee.sunchenbin.mybatis.actable.annotation.Column;
import com.gitee.sunchenbin.mybatis.actable.annotation.Table;
import com.gitee.sunchenbin.mybatis.actable.constants.MySqlTypeConstant;
import lombok.Data;



/**
 * @ClassName Test
 * @Description
 * @Author Administrator
 * @Date 2020/10/30 0030 16:48
 * @Version 1.0
 */

@Data
@Table(name = "aaaaaaaaaaaaaa")
public class Test {


  @Column(name = "role_id", type = MySqlTypeConstant.INT, isNull = false,isKey = true, isAutoIncrement = true, comment = "自增id")
  private Long id;

  @Column(name = "name", type = MySqlTypeConstant.VARCHAR, isNull = false, length = 20, comment = "角色名字")
  private String name;

  @Column(name = "name_zh", type = MySqlTypeConstant.VARCHAR, isNull = true, length = 20, comment = "角色的中文名字")
  private String name_zh;
}

運行日志

到此這篇關(guān)于mybatis自動建表的實現(xiàn)方法的文章就介紹到這了,更多相關(guān)mybatis 自動建表內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • 8種常見的Java不規(guī)范代碼

    8種常見的Java不規(guī)范代碼

    本文主要介紹了8種常見的Java不規(guī)范代碼。具有很好的參考價值,下面跟著小編一起來看下吧
    2017-01-01
  • Java8 中的ParallelStream

    Java8 中的ParallelStream

    這篇文章主要介紹了Java8 中的并行流 ParallelStreams,Java8并行流ParallelStream和Stream的區(qū)別就是支持并行執(zhí)行,提高程序運行效率。下面就來看看文章內(nèi)容具體介紹吧
    2021-10-10
  • spring常用注解開發(fā)一個RESTful接口示例

    spring常用注解開發(fā)一個RESTful接口示例

    這篇文章主要為大家介紹了使用spring常用注解開發(fā)一個RESTful接口示例,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步
    2022-03-03
  • Java面試之動態(tài)規(guī)劃與組合數(shù)

    Java面試之動態(tài)規(guī)劃與組合數(shù)

    這篇文章主要介紹了Java面試之動態(tài)規(guī)劃與組合數(shù)的相關(guān)知識,非常不錯,具有一定的參考借鑒價值,需要的朋友可以參考下
    2019-09-09
  • 解決SpringBoot的@DeleteMapping注解的方法不被調(diào)用問題

    解決SpringBoot的@DeleteMapping注解的方法不被調(diào)用問題

    這篇文章主要介紹了解決SpringBoot的@DeleteMapping注解的方法不被調(diào)用問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2023-01-01
  • SpringMVC中的攔截器詳解及代碼示例

    SpringMVC中的攔截器詳解及代碼示例

    這篇文章主要介紹了SpringMVC中的攔截器詳解及代碼示例,分享了相關(guān)代碼示例,小編覺得還是挺不錯的,具有一定借鑒價值,需要的朋友可以參考下
    2018-02-02
  • ZIP4j 壓縮與解壓的實例詳解

    ZIP4j 壓縮與解壓的實例詳解

    這篇文章主要介紹了ZIP4j 壓縮與解壓的實例詳解的相關(guān)資料,希望通過本文能幫助到大家,需要的朋友可以參考下
    2017-10-10
  • IDEA插件之mybatisx插件使用教程(超詳細(xì)!)

    IDEA插件之mybatisx插件使用教程(超詳細(xì)!)

    MybatisX 是一款基于IDEA的快速開發(fā)插件,為效率而生,下面這篇文章主要給大家介紹了關(guān)于IDEA插件之mybatisx插件使用的相關(guān)資料,文中通過圖文介紹的非常詳細(xì),需要的朋友可以參考下
    2023-06-06
  • Mybatis實現(xiàn)SQL存儲流程詳解

    Mybatis實現(xiàn)SQL存儲流程詳解

    MyBatis作為一款優(yōu)秀的持久層框架,它支持自定義SQL、存儲過程以及高級映射。它免除了幾乎所有的JDBC代碼以及設(shè)置參數(shù)和獲取結(jié)果集的工作
    2023-03-03
  • 解決在SpringBoot中使用@Value取不到值的問題

    解決在SpringBoot中使用@Value取不到值的問題

    這篇文章主要給大家分享解決在SpringBoot中使用@Value取不到值的問題,文中有詳細(xì)的解決代碼供大家參考,具有一定的參考價值,需要的朋友可以參考下
    2023-09-09

最新評論