代码拉取完成,页面将自动刷新
由于本工具是基于Springboot+Mybatis
环境运行,所以使用本工具的童鞋,我一律认为你们已经熟练掌握Springboot+Mybatis
的使用,并且已经搭建好环境
<dependency>
<groupId>cn.jasonone.autotable</groupId>
<artifactId>auto-table-spring-boot-starter</artifactId>
<version>1.0.3</version>
</dependency>
@Data
@Table(name = "user_info", comment = "用户信息表")
public class UserInfo {
@Column(autoincrement = true,primaryKey = true,comment = "主键")
private Integer id;
@Column(length = 50,primaryKey = true,notNull = true,comment = "用户名")
private String username;
@Column(length = 32,notNull = true,comment = "密码")
private String password;
@Column(length = 1,defaultValue = "1")
private Integer status;
@Column(name="create_time")
private Date createTime;
@Column(name="update_time",type = JdbcType.TIMESTAMP)
private Date updateTime;
}
application.yml
配置auto-table:
catalog: test #表类型
注: 表类型比较抽象,因为它在不同数据库中有不同的理解,比如在Mysql中代表的是数据库名称,而Oracle中代表的则是数据库实例名
@EnableAutoTable //启用AutoTable
@SpringBootApplication
public class AutoTableExampleApplication {
public static void main(String[] args) {
SpringApplication.run(AutoTableExampleApplication.class, args);
}
}
auto-table:
type: none #运行模式
temp-column-name: $_auto_table_temp #临时字段,用来解决无法创建空表的问题
handlers:
create: cn.jasonone.at.type.CreateAutoTableType #create模式处理器
update: cn.jasonone.at.type.UpdateAutoTableType #update模式处理器
jdbc-types: #对应的数据类型模版字符串
mysql: #数据库类型,如: mysql,oracle 等等
varchar: varchar(@{length>0?length:255})
float: float(@{length>0?length:11},@{decimal>0?decimal:2})
double: double(@{length>0?length:11},@{decimal>0?decimal:2})
integer: int(@{length>0?length:11})
bigint: bigint(@{length>0?length:11})
bit: bit(1)
timestamp: timestamp
date: datetime
java-types: #在@Column注解中type属性留空时,会自动根据当前属性的java类型,进行映射,以下是映射规则
java.lang.String: varchar
java.util.Date: date
java.lang.Integer: integer
java.lang.Double: double
java.lang.Float: float
java.lang.Long: bigint
java.lang.Short: integer
java.lang.Boolean: bit
java.sql.Timestamp: timestamp
sql: #不同数据库的DDL模版
mysql:
create-primary-key: alter table `@{catalog}`.`@{tableName}` drop primary key, add primary key (@{for(pk:primaryKeys ,) '`'+pk+'`'}) USING BTREE
create-column-sql: alter table `@{catalog}`.`@{tableName}` add `@{columnName}` @{type} @{notNull?'not null':''} @{autoincrement?'primary key AUTO_INCREMENT':''} @{defaultValue?("default '"+defaultValue+"'"):''} @{comment?(" comment '"+comment+"'"):''}
create-table-sql: create table `@{catalog}`.`@{tableName}`(`@{tempColumnName}` int) comment '@{comment}'
drop-column-sql: alter table `@{catalog}`.`@{tableName}` drop `@{columnName}`
drop-table-sql: drop table `@{catalog}`.`@{tableName}`
update-column-sql: alter table `@{catalog}`.`@{tableName}` modify `@{columnName}` @{type} @{notNull?'not null':''} @{comment?(" comment '"+comment+"'"):''}
auto-table:
catalog: test #表类型
注: 表类型比较抽象,因为它在不同数据库中有不同的理解,比如在Mysql中代表的是数据库名称,而Oracle中代表的则是数据库实例名
#{表达式 ? 分支1 : 分支2}
如果值无意义,则使用默认值
#{值!默认值}
#{for(迭代变量:迭代集合 分隔符) 迭代内容}
cn.jasonone.at.type.AutoTableType
接口,以下为默认实现的模式处理器: handlers:
create: cn.jasonone.at.type.CreateAutoTableType #create模式处理器
update: cn.jasonone.at.type.UpdateAutoTableType #update模式处理器
cn.jasonone.at.enums.ATType
对象./**
* 生成模式
* @author Jason
*
*/
public enum ATType {
/**
* 创建模式: 将删除所有已存在的表,重新创建,会清除所有数据
*/
CREATE,
/**
* 更新模式: 保留已存在的表以及字段,不针对字段或其结构进行修改,不影响数据
*/
UPDATE,
/**
* 默认模式: 不做任何操作
*/
NONE;
}
注:该对象之所以写成枚举,是为了大家在配置时能够具有友好的提示功能
auto-table.base-bean-packages
,提升扫描速度,如未配置将自动扫描当前项目中的实体,而不再扫描整个classpath中的实体此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。