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[前导零] ...
随机推荐
- JAVA常用加密解密算法Encryption and decryption
加密,是以某种特殊的算法改变原有的信息数据,使得未授权的用户即使获得了已加密的信息,但因不知解密的方法,仍然无法了解信息的内容.大体上分为双向加密和单向加密,而双向加密又分为对称加密和非对称加密(有些 ...
- 【数据结构】算法 LinkList (Remove Nth Node From End of List)
删除链表中倒数第n个节点 时间复杂度要控制在O(n)Solution:设置2个指针,一个用于确定删除节点的位置,一个用于计算倒数间距n.移动时保持2个指针同时移动. public ListNode r ...
- px和em的区别, css权重
PX特点:px像素(Pixel).相对长度单位.像素px是相对于显示器屏幕分辨率而言的. EM特点 1. em的值并不是固定的:2. em会继承父级元素的字体大小. 优先级:!important> ...
- Log4j 2使用教程二 【详解】
配置 Log4j 2的配置可以通过4种方式中的1种完成: 1.通过使用XML,JSON,YAML或属性格式编写的配置文件. 2.以编程方式,通过创建一个ConfigurationFactory和配置实 ...
- angularjs简单介绍和特点
首先angular是一个mvc框架, 使用mvc解耦, 采用model, controller以及view的方式去组织代码, 会将一个html页面分成若干个模块, 每个模块都有自己的scope, se ...
- polyfillJS生成promise对象
https://cdn.jsdelivr.net/npm/promise-polyfill@8/dist/polyfill.min.js
- (2018干货系列二)最新HTML5学习路线整合
怎么学HTML5 HTML5是万维网的核心语言,标准通用标记语言下的一个应用超文本标记语言(HTML)的第五次重大修改,一方面提升了用户体验,另一方面HTML5技术跨平台,适配多终端,改变了传统开发者 ...
- 移动端开发调试工具神器--Weinre使用方法
前端开发调试必备: DOM操作断点调试: debugger断点调试: native方法hook(个人暂时还没有试过,不知效果如何): 远程映射本地测试: Weinre移动调试(详细介绍): 像Dom断 ...
- 5.JAVA基础复习——JAVA中的static关键字作用与用法
static关键字: 特点: 1.static是一个修饰符,用于修饰成员.(成员变量,成员函数)static修饰的成员变量 称之为静态变量或类变量. 2.static修饰的成员被所有的对象共享. 3. ...
- jdbc之工具类DBUtil的使用
首先回顾一下jdbc的使用方法: 1. 注册驱动 2. 建立连接 3. 建立statement 4. 定义sql语句 5. 执行sql语句,如果执行的是查询需遍历结果集 6. 关闭连接 其中建立连接和 ...