A.CTable 自动创建数据表
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 自动创建数据表的更多相关文章
- SpringBoot+Mybatis 自动创建数据表(适用mysql)
Mybatis用了快两年了,在我手上的发展史大概是这样的 第一个阶段 利用Mybatis-Generator自动生成实体类.DAO接口和Mapping映射文件.那时候觉得这个特别好用,大概的过程是这样 ...
- springboot项目启动-自动创建数据表
很多时候,我们部署一个项目的时候,需要创建大量的数据表.例如mysql,一般的方法就是通过source命令完成数据表的移植,如:source /root/test.sql.如果我们需要一个项目启动后, ...
- 学习笔记之--Navicat Premium创建数据表
1.打开Navicat Premium,点击连接,选择MySQL,创建新连接.输入安装MySQL是的用户名和密码.点击确定. 2.admin数据连接已经创建成功.下面为admin新建数据库,输入数据库 ...
- PL/SQL创建数据表空间
创建数据表空间create tablespace stbss datafile 'E:\oracle\product\10.2.0\oradata\orcl\stbss_temp01.dbf' siz ...
- MySQL创建数据表
* 创建数据表 * * * 一.什么是数据表 * * * * 二.创建数据表的SQL语句模型 * * DDL * * ...
- MySQL 创建数据表
MySQL 创建数据表 创建MySQL数据表需要以下信息: 表名 表字段名 定义每个表字段 语法 以下为创建MySQL数据表的SQL通用语法: CREATE TABLE table_name (col ...
- Mysql学习(慕课学习笔记4)创建数据表、查看数据表、插入记录
创建数据表 Create table [if not exists] table_name(column_name data_type,…….) UNSIGNED 无符号SIGNED 有符号 查看创建 ...
- ThinkPHP 自动创建数据、自动验证、自动完成详细例子介绍(十九)
原文:ThinkPHP 自动创建数据.自动验证.自动完成详细例子介绍(十九) 1:自动创建数据 //$name=$_POST['name']; //$password=$_POST['password ...
- MySQL学习笔记_3_MySQL创建数据表(中)
MySQL创建数据表(中) 三.数据字段属性 1.unsigned[无符号] 可以让空间增加一倍 比如可以让-128-127增加到0-255 注意:只能用在数值型字段 2.zerofill[前导零] ...
随机推荐
- 与图论的邂逅04:LCT
本着对数据结构这一块东西的一股兴趣,最近在集训的百忙之中抽空出来学LCT,终于学懂了这个高级玩意儿. 前置知识:Splay和树链剖分 Splay挺复杂的......这里就先不写,不然篇幅太大.树链剖分 ...
- arcgis for JavaScript API 4.5与4.3的区别
arcgis 4.5与4.3区别: 鉴于本人使用4.3时间比较久,而arcgis for JavaScript API于9月28日推出了4.5版本,但是直接更换4.5的init.js会出现意想不到的错 ...
- win7插着网线开机卡死,拔下网线开机正常
公司的部分win7电脑插着网线开机,进到桌面后网络图标转圈圈卡住.控制面板,启动项,任务管理器等都打不开.把网线拔下后再开机,电脑正常进入系统,后再插上网线就能正常上网了.被这个问题困扰了很久,百度也 ...
- 修改AD FS
https://technet.microsoft.com/en-us/windows-server-docs/identity/ad-fs/operations/ad-fs-user-sign-in ...
- git 本地提交代码到 github 远程库,没有弹框 github login
git 本地提交代码到 github 远程库,没有弹框 github login: 原因: win10 有个凭据管理器,给保存了历史登陆用户名密码,导致无法切换用户. 解决办法: 删除历史登陆用户 ...
- 使用jconsole监控JVM内存
首先声明:此篇博文分析的是JDK1.8. JVM内存区域总体分两类:heap区和非heap区.Jconsole中对内存划分为同样的结构,如下: heap区又分为: - Eden Space(伊甸园) ...
- oracle:SQL时间段
oracle: SQL时间段 CREATEDATE between to_date('" + startDate + " 00:00:00','yyyy-mm-dd hh24:mi ...
- Lamda Expression
Expression<Func<Student, bool>> filter=s=>s.Name.Contains("a") && s ...
- js 对url进行某个参数的删除,并返回url
两种情况 1对当前页面的url进行操作 function funcUrlDel(name){ var loca = window.location; var baseUrl = loca.origin ...
- 20180519001 - DataTable Group by功能参考
DataSet6 = DataSet1.Copy(); DataRow[] dr = DataSet6.Tables[0].Select(" 完工状态 = '完工异常' "); D ...