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[前导零] ...
随机推荐
- Mybatis的bind动态SQL
bind标签用于在SQL执行的上下文中绑定一个变量,方便在后续中直接使用:下面的例子中将name参数拼接成模糊查询需要的字符串然后和bindName绑定,在后面的使用中可以直接使用bindName变量 ...
- windows CMD常用命令
命令简介 cmd是command的缩写.即命令行 . 虽然随着计算机产业的发展,Windows 操作系统的应用越来越广泛,DOS 面临着被淘汰的命运,但是因为它运行安全.稳定,有的用户还在使用,所以一 ...
- 爬取豆瓣电影影评,生成wordcloud词云,并利用监督学习根据评论自动打星
本文的完整源码在git位置:https://github.com/OceanBBBBbb/douban-ml 爬取豆瓣影评 爬豆瓣的影评比较简单,豆瓣没有做限制,甚至你都不用登陆就可以看全部,我这里用 ...
- Vuex 2.0 深入简出
最近面试充斥了流行框架Vue的各种问题,其中Vuex的使用就相当有吸引力.下面我就将自己深入简出的心得记录如下: 1.在vue-init webpack project (创建vue项目) 2.src ...
- Orange Greenworks
对于steam游戏开发,成就功能是必不可少的. 而Rpgmaker系列无自带的插件或指令实现,且多数游戏作者并无熟练的脚本编写能力,所以~~ 我们要使用外部插件----Orange Work. 这里 ...
- jdk5升级至jdk8框架版本选型
spring-framework-4.3.18.RELEASE 4.3.x+:JDK8 Spring JDK Version Range Spring Framework 5.1.x: JDK 8- ...
- 2018.2.21 Python 初学习
折腾了一天,一直在用CMD学习Python写Hello World.偶然间发现可以用Pycharm.也算是给后面想学习的人提个醒,方便省事许多. format()使用方法. age = 20name ...
- python format()用法
转自 https://www.cnblogs.com/gide/p/6955895.html python2.6开始,新增了一种格式化字符串的函数str.format(),此函数可以快速处理各种字符串 ...
- 三月pat(转)
转自https://blog.csdn.net/weixin_40688413/article/details/88082779 担心别人删除了就找不到了.因为九月要考. 7-1 Sexy Prime ...
- dynamic的使用
一.在没有dynamic之前,我们想要获取返回object对象里的属性的值时,使用反射的方法来获取该对象的属性值. class Program { static void Main(string[] ...