A tool for generating creating table script in Mysql.
- for example:
@TableName("tb_yq_user")
@Desc("用户表")
public class UserEntity {
@PrimaryKey
long id;
@UniqueKey("IDX_YQ_USER_UID")
@Desc("账号")
String uid;
//omit set,get method
}
- create main method
- invoke SqlUtil.writeSqlToFile method
- for example:
public class Test {
public static void main(String[] args) {
String path=System.getProperty("user.dir")+File.separator+"schema.sql";
Class [] classes={UserEntity.class};
SqlUtil.writeSqlToFile(classes,path);
}
}
- we can find a file defined above(named
schema.sql
). - for example:
DROP TABLE IF EXISTS `tb_yq_user`;
CREATE TABLE `tb_yq_user` (
`id` bigInt(20) NOT NULL AUTO_INCREMENT COMMENT '主键' ,
`uid` varchar(64) DEFAULT '' COMMENT '账号',
PRIMARY KEY (`id`),
UNIQUE KEY `IDX_YQ_USER_UID` (`uid`)
)ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='用户表';
- PrimaryKey:primary key
- UniqueKey:unique index
- Key:normal index
- TaleName:declare table's name
- Desc :add comment(table name or field comment)
- Ignore:ignore the field in Bean