a tool to generate java files from create table sql
- In view of Java language features, it supports configurable template files to generate corresponding java code
sh build.sh
Or download the compiled file
switch to sql2java folder like this:
├── config.json
├── sql2java
├── table.sql
└── templates
├── controller.tpl
├── dao.tpl
├── entity.tpl
├── mapper.tpl
├── request.tpl
├── service.tpl
└── service_impl.tpl
run
./sql2java table.sql
or
./sql2java table.sql config.json
output
└── com
└── yunx
└── ldct
├── controller
│ ├── ProductController.java
│ └── UserController.java
├── dao
│ ├── ProductDao.java
│ └── UserDao.java
├── entity
│ ├── ProductEntity.java
│ └── UserEntity.java
├── mapper
│ ├── ProductMapper.java
│ └── UserMapper.java
├── model
│ └── request
│ ├── ProductRequest.java
│ └── UserRequest.java
└── service
├── ProductService.java
├── UserService.java
└── impl
├── ProductServiceImpl.java
└── UserServiceImpl.java
- lower case
- only support .tpl file
- support underline naming; service_impl.tpl -> XxServiceImpl.java
- template placeholder definition: {{.YourConfigKey}}
{
"BasePackage": "project base package, example com.yunx.base.abc",
"BasePath": "The path to place the java2sql file, templates / output, default java2sql file current dir",
"Author": "author name, default your system username",
"ParentEntityName": "Entity parent class name, like BaseEntity",
"ParentEntityFields": "Entity parent class fields, like id, createBy and so on, this fields will not be generated",
"TablePrefix": "the table prefix that you dont want to act on your EntityName, t_ -> t_user -> UserEntity ",
"OutputFormat": "true organizing directories by package path "
}
function | description | example |
---|---|---|
toLower | returns with all Unicode letters mapped to their lower case | {{.EntityName | toLower}} |
toUpper | returns with all Unicode letters mapped to their upper case | {{.EntityName | toUpper}} |
the next stage will distinguish between built-in configurations and support for user-defined configurations