Skip to content

lywhlao/sqlHelper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sqlHelper

A tool for generating creating table script in Mysql.

Usage

1.add annotation to Java Bean

  • 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
 }
 

2.create sql script

  • 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);
    }
}

3.get sql script

  • 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='用户表';

Appendix

annotation

  • 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

About

A tool for generating Mysql DDL .

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages