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[前导零] ...
随机推荐
- appium 3 跑起来
1. 代码如下: from appium import webdriver capabilitise = { "platformName": "Android" ...
- Kafka笔记8(管理Kafka)
使用kafka-topic.sh工具可以执行大部分操作 创建/修改/删除/查看集群里的主题.要使用全部功能,需要通过--zookeeper参数提供zookeerper连接字符串 创建主题: 创建主 ...
- 扎实学Java之数组与方法
什么是数组? 数组是一个容器,用来存储多个数据(数据类型相同) 声明一个数组就是在内存中开辟一串连续的空间 数组的结构和基本要素 标识符:数组的名称,用于区分不同的数组 数组元素:向数组中存放的数据 ...
- 《linux就该这么学》第十七节课:第18,19,23章,mariadb数据库、PXE无人值守安装系统和openldap目录服务。
第23章 (借鉴请改动) openldap数据的特点:1.短小.2.读取次数较多 上述说明: openLDAP服务端配置: 1.yum install -y openldap openldap ...
- Go 初体验 - 闭包的几种情况
闭包: 闭包是可以包含自由(未绑定到特定对象)变量的代码块,这些变量不在这个代码块内或者任何全局上下文中定义,而是在定义代码块的环境中定义.要执行的代码块(由于自由变量包含在代码块中,所以这些自由变量 ...
- nmon安装与使用
一.检查安装环境 1,# uname –a (查看操作系统信息,所检查服务器为64位操作系统) Linux jmeter 2.6.32-504.el6.x86_64 #1 SMP Wed Oct 15 ...
- Linux基础篇
Linux入门 2.1 Linux介绍 1)Linux是一款操作系统,特点:免费.开源.安全.高效.稳定.处理高并发非常强悍,半年至一年重启一次机即可,比Windows强悍,现在很多企业级项目都部署到 ...
- cxf整合spring中出现的错误
Caused by: java.lang.ClassNotFoundException: javax.wsdl.extensions.ElementExtensible at org.apache.c ...
- nodejs笔记之连接mysql数据库
1.安装mysql模块: npm install mysql 2.引入mysql模块 创建一个server.js文件 const http = require("http"); c ...
- ltp-ddt nor_mtd_dd_rw_jffs2
nor_mtd_dd_rw_jffs2运行报错 error getting mtd part number: $part get_mtd_biggest_part for $DEVICE_TYPE: ...