1.添加依赖

<!--  A.CTable 自动创建数据表  -->
<dependency>
<groupId>com.gitee.sunchenbin.mybatis.actable</groupId>
<artifactId>mybatis-enhance-actable</artifactId>
<version>1.0.4</version>
</dependency>

2.配置application.properties

mybatis.table.auto=update
mybatis.model.pack=com.boot.entity
mybatis.database.type=mysql

2.创建config

MybatisEntity 
/**
* <p>Title: MybatisEntity.java</p>
* <p>Description: </p>
* @author zhouyue
* @date 2018年11月29日
* @version 1.0
*/
package com.boot.entity; /**
* <p>Title: MybatisEntity</p>
* <p>Description: </p>
* @author zhouyue
* @date 2018年11月29日
*/ import java.sql.Date; import com.gitee.sunchenbin.mybatis.actable.annotation.Column;
import com.gitee.sunchenbin.mybatis.actable.annotation.Table;
import com.gitee.sunchenbin.mybatis.actable.command.BaseModel;
import com.gitee.sunchenbin.mybatis.actable.constants.MySqlTypeConstant; @Table(name = "MybatisEntity")
public class MybatisEntity extends BaseModel{ private static final long serialVersionUID = 5199200306752426433L; @Column(name = "id",type = MySqlTypeConstant.INT,length = 11,isKey = true,isAutoIncrement = true)
private Integer id; @Column(name = "name",type = MySqlTypeConstant.VARCHAR,length = 111)
private String name; @Column(name = "description",type = MySqlTypeConstant.TEXT)
private String description; @Column(name = "create_time",type = MySqlTypeConstant.DATETIME)
private Date create_time; @Column(name = "update_time",type = MySqlTypeConstant.DATETIME)
private Date update_time; @Column(name = "number",type = MySqlTypeConstant.BIGINT,length = 5)
private Long number; @Column(name = "lifecycle",type = MySqlTypeConstant.CHAR,length = 1)
private String lifecycle; @Column(name = "dekes",type = MySqlTypeConstant.DOUBLE,length = 5,decimalLength = 2)
private Double dekes; public Integer getId(){
return id;
} public void setId(Integer id){
this.id = id;
} public String getName(){
return name;
} public void setName(String name){
this.name = name;
} public Date getCreate_time(){
return create_time;
} public void setCreate_time(Date create_time){
this.create_time = create_time;
} public Date getUpdate_time(){
return update_time;
} public void setUpdate_time(Date update_time){
this.update_time = update_time;
} public String getDescription(){
return description;
} public void setDescription(String description){
this.description = description;
} public Long getNumber(){
return number;
} public void setNumber(Long number){
this.number = number;
} public String getLifecycle(){
return lifecycle;
} public void setLifecycle(String lifecycle){
this.lifecycle = lifecycle;
} public Double getDekes(){
return dekes;
} public void setDekes(Double dekes){
this.dekes = dekes;
} }

  mybatisTableConfig

/**
* <p>Title: MybatisTableConfig.java</p>
* <p>Description: </p>
* @author zhouyue
* @date 2018年11月29日
* @version 1.0
*/
package com.boot.config; 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; /**
* <p>Title: MybatisTableConfig</p>
* <p>Description: </p>
* @author zhouyue
* @date 2018年11月29日
*/
@Configuration
@ComponentScan(basePackages = {"com.gitee.sunchenbin.mybatis.actable.manager.*"})
public class MybatisTableConfig { @Value("${spring.datasource.driver-class-name}")
private String driver; @Value("${spring.datasource.url}")
private String url; @Value("${spring.datasource.username}")
private String username; @Value("${spring.datasource.password}")
private String password; @Bean
public PropertiesFactoryBean configProperties() throws Exception{
PropertiesFactoryBean propertiesFactoryBean = new PropertiesFactoryBean();
PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
propertiesFactoryBean.setLocations(resolver.getResources("classpath*:application.properties"));
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.boot.entity.*");
return sqlSessionFactoryBean;
} }

创建entity

/**
* <p>Title: MybatisEntity.java</p>
* <p>Description: </p>
* @author zhouyue
* @date 2018年11月29日
* @version 1.0
*/
package com.boot.entity; /**
* <p>Title: MybatisEntity</p>
* <p>Description: </p>
* @author zhouyue
* @date 2018年11月29日
*/ import java.sql.Date; import com.gitee.sunchenbin.mybatis.actable.annotation.Column;
import com.gitee.sunchenbin.mybatis.actable.annotation.Table;
import com.gitee.sunchenbin.mybatis.actable.command.BaseModel;
import com.gitee.sunchenbin.mybatis.actable.constants.MySqlTypeConstant; @Table(name = "MybatisEntity")
public class MybatisEntity extends BaseModel{ private static final long serialVersionUID = 5199200306752426433L; @Column(name = "id",type = MySqlTypeConstant.INT,length = 11,isKey = true,isAutoIncrement = true)
private Integer id; @Column(name = "name",type = MySqlTypeConstant.VARCHAR,length = 111)
private String name; @Column(name = "description",type = MySqlTypeConstant.TEXT)
private String description; @Column(name = "create_time",type = MySqlTypeConstant.DATETIME)
private Date create_time; @Column(name = "update_time",type = MySqlTypeConstant.DATETIME)
private Date update_time; @Column(name = "number",type = MySqlTypeConstant.BIGINT,length = 5)
private Long number; @Column(name = "lifecycle",type = MySqlTypeConstant.CHAR,length = 1)
private String lifecycle; @Column(name = "dekes",type = MySqlTypeConstant.DOUBLE,length = 5,decimalLength = 2)
private Double dekes; public Integer getId(){
return id;
} public void setId(Integer id){
this.id = id;
} public String getName(){
return name;
} public void setName(String name){
this.name = name;
} public Date getCreate_time(){
return create_time;
} public void setCreate_time(Date create_time){
this.create_time = create_time;
} public Date getUpdate_time(){
return update_time;
} public void setUpdate_time(Date update_time){
this.update_time = update_time;
} public String getDescription(){
return description;
} public void setDescription(String description){
this.description = description;
} public Long getNumber(){
return number;
} public void setNumber(Long number){
this.number = number;
} public String getLifecycle(){
return lifecycle;
} public void setLifecycle(String lifecycle){
this.lifecycle = lifecycle;
} public Double getDekes(){
return dekes;
} public void setDekes(Double dekes){
this.dekes = dekes;
} }

代码地址

https://github.com/zyf970617/mybatis-auto-create-table.git

A.CTable 自动创建数据表的更多相关文章

  1. SpringBoot+Mybatis 自动创建数据表(适用mysql)

    Mybatis用了快两年了,在我手上的发展史大概是这样的 第一个阶段 利用Mybatis-Generator自动生成实体类.DAO接口和Mapping映射文件.那时候觉得这个特别好用,大概的过程是这样 ...

  2. springboot项目启动-自动创建数据表

    很多时候,我们部署一个项目的时候,需要创建大量的数据表.例如mysql,一般的方法就是通过source命令完成数据表的移植,如:source /root/test.sql.如果我们需要一个项目启动后, ...

  3. 学习笔记之--Navicat Premium创建数据表

    1.打开Navicat Premium,点击连接,选择MySQL,创建新连接.输入安装MySQL是的用户名和密码.点击确定. 2.admin数据连接已经创建成功.下面为admin新建数据库,输入数据库 ...

  4. PL/SQL创建数据表空间

    创建数据表空间create tablespace stbss datafile 'E:\oracle\product\10.2.0\oradata\orcl\stbss_temp01.dbf' siz ...

  5. MySQL创建数据表

    *  创建数据表 * *       *      一.什么是数据表 * *           * *      二.创建数据表的SQL语句模型 * *          DDL * *       ...

  6. MySQL 创建数据表

    MySQL 创建数据表 创建MySQL数据表需要以下信息: 表名 表字段名 定义每个表字段 语法 以下为创建MySQL数据表的SQL通用语法: CREATE TABLE table_name (col ...

  7. Mysql学习(慕课学习笔记4)创建数据表、查看数据表、插入记录

    创建数据表 Create table [if not exists] table_name(column_name data_type,…….) UNSIGNED 无符号SIGNED 有符号 查看创建 ...

  8. ThinkPHP 自动创建数据、自动验证、自动完成详细例子介绍(十九)

    原文:ThinkPHP 自动创建数据.自动验证.自动完成详细例子介绍(十九) 1:自动创建数据 //$name=$_POST['name']; //$password=$_POST['password ...

  9. MySQL学习笔记_3_MySQL创建数据表(中)

    MySQL创建数据表(中) 三.数据字段属性 1.unsigned[无符号] 可以让空间增加一倍 比如可以让-128-127增加到0-255 注意:只能用在数值型字段 2.zerofill[前导零] ...

随机推荐

  1. C++模板的要点

    1.函数模板与普通函数的区别: 普通函数可以进行自动类型转化,而函数模板不可以. 举个例子 //函数模板 template<class T> void show(T a,T b){ cou ...

  2. dede织梦手机站m文件夹功能基础详解

    织梦2015年6月8日更新后,就添加了很多针对手机移动端的设计,最大的设计就是添加了生成二维码的织梦标签和织梦手机模板功能,织梦更新后,默认的 default模板中就包含手机模板,所以我们可以给织梦网 ...

  3. 279. Perfect Squares(动态规划)

    Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 1 ...

  4. poj1456

    题目大意:给定一些物品以及他们的价值和时间w.t,表示物品在时间t内售出能得到w 的价值,一天只能出售一件物品,求最大利润: 非常有意思的一道并查集的思想题 首先以价值为关键字排序,类似于贪心的思想, ...

  5. druid数据源连接oracle10g报错:not support oracle driver 1.0

    jdbc驱动与数据库版本不一致,去数据库服务器的安装目录(cd $ORACLE_HOME)找jdbc->lib->ojdbcX.jar 替换到你项目中即可. oracle目录lib下jar ...

  6. CentOS7运行报错kernel:NMI watchdog: BUG: soft lockup - CPU#0 stuck for 26s

    CentOS内核,对应的文件是/proc/sys/kernel/watchdog_thresh.CentOS内核和标准内核还有一个地方不一样,就是处理CPU占用时间过长的函数,CentOS下是watc ...

  7. 用python写栈

    class StackFullError(Exception): pass class StackEmptyError(Exception): pass class Stack: def __init ...

  8. 信步漫谈之Git—环境搭建及入门

    一.初识Git Git是一套优秀的分布式版本控制系统(区别于SVN和CVS,这两者是集中式版本控制系统).分布式和集中式版本控制系统的区别:1)集中式版本控制系统:版本库是集中存放在中央服务器的,而干 ...

  9. Android SDK Manager for Mac 在线更新镜像地址截至2017-10-01亲测有效

    虽然国内google被墙了,但仍可利用国内的某些镜像网站实现Android SDK在线更新,使用方法如下: 1.启动 Android SDK Manager ,打开主界面,依次选择『Tools』.『O ...

  10. [Python数据挖掘]第7章、航空公司客户价值分析

    一.背景和挖掘目标 二.分析方法与过程 客户价值识别最常用的是RFM模型(最近消费时间间隔Recency,消费频率Frequency,消费金额Monetary) 1.EDA(探索性数据分析) #对数据 ...