国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

您的位置:首頁技術文章
文章詳情頁

mybatis自動建表的實現方法

瀏覽:3日期:2023-10-21 17:55:24

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;}

運行日志

mybatis自動建表的實現方法

mybatis自動建表的實現方法

到此這篇關于mybatis自動建表的實現方法的文章就介紹到這了,更多相關mybatis 自動建表內容請搜索好吧啦網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持好吧啦網!

標簽: Mybatis 數據庫
相關文章:
主站蜘蛛池模板: 欧美高清videossex19 | 国产精品无打码在线播放9久 | 波多野结衣一区二区三区在线观看 | 亚洲第一中文 | 精品真实国产乱文在线 | 深夜福利视频在线看免费 | 女人被男人躁得好爽免费视频免费 | 韩国精品欧美一区二区三区 | 精品国产欧美精品v | 欧美成人a大片 | 日韩成人免费在线视频 | 国产欧美成人不卡视频 | 久久精品一区二区三区不卡牛牛 | 国产精品九九视频 | 国产伦精品一区三区视频 | 亚洲综合在线视频 | 俄罗斯三级毛片 | 9lporm自拍视频在线 | 国产21区 | 亚洲精彩视频在线观看 | 国产精品精品国产一区二区 | 亚州综合网 | 亲子乱子伦xxxx | 伊人久久青草青青综合 | 久久国产成人精品 | 播放一级毛片 | 日韩精品一区二区三区中文字幕 | 亚洲国产老鸭窝一区二区三区 | 在线观看视频99 | 中文字幕久久久 | 亚洲国产系列久久精品99人人 | 亚洲精品一区二区三区在线播放 | 久久福利资源站免费观看i 久久高清精品 | 一级毛片在线播放 | 欧美freesex10一13黑人 | 亚洲一级高清在线中文字幕 | 成人在线手机视频 | 久久国产精品-国产精品 | 美国三级毛片 | 亚洲视频一区二区在线观看 | 国产精品久久久久久久久久久不卡 |