Java code generator

Full automatic code generator Project address https://github.com/GitHub-Laziji/mybatis-generator The code template is located under resources and can ...

Full automatic code generator

Project address

https://github.com/GitHub-Laziji/mybatis-generator

The code template is located under resources and can be modified as needed

The first template is based on commons-mybatis If it is not suitable, you can modify the template or select another template

configuration file

Create the application-$.yml file under resources, $ at will, for example: application-example.yml, you can create multiple

The contents of the configuration file are as follows, fill in the database configuration and the package name of the generated code

Template file mapping is used to customize the package format and file name of the generated file

Dynamic properties contain

  • package file path for example: com/xxx/xxx
  • The class name is obtained by changing the table name to the hump name
  • class name suffix DO or VO

Generally, it can be configured as follows

Now there are two templates in the project template.path. You can choose mybatis or mybatis default

It can also be expanded by itself

spring: datasource: url: jdbc:mysql://xxx.xxx.xxx.xxx:3306/xxxx?characterEncoding=utf-8 username: xxxxxx password: xxxxxx generator: package: com.xxx.xxx template: path: mybatis mapping: | Model.java.vm: main/java//database/model/.java Query.java.vm: main/java//database/query/Query.java Dao.java.vm: main/java//database/dao/.java Service.java.vm: main/java//database/service/Service.java Mapper.xml.vm: main/resources/mapper/Mapper.xml
Use

Create a test class under the test file

  • @Fill in the name of the profile name in ActiveProfiles("example")
  • tableNames are the tables that need to be generated. There can be multiple
  • zipPath code export path

Call generatorService.generateZip and the incoming parameter can be the table name array String [] or TableItem []

Run test method

package pg.laziji.generator; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit4.SpringRunner; import pg.laziji.generator.mybatis.GeneratorService; import javax.annotation.Resource; import java.io.IOException; @ActiveProfiles("example") @RunWith(SpringRunner.class) @SpringBootTest public class ExampleTest { @Resource private GeneratorService generatorService; @Test public void test(){ String zipPath = "/home/code.zip"; // String[] tableNames = new String[]{"table1","table2"}; // generatorService.generateZip(tableNames,zipPath); TableItem[] tableItems = new TableItem[]{ new TableItem("table1", "TableA"), new TableItem("table2", "TableB") }; generatorService.generateZip(tableItems,zipPath); } }

Welcome to my blog public address.

3 December 2019, 10:28 | Views: 1130

Add new comment

For adding a comment, please log in
or create account

0 comments