@@ -149,33 +149,76 @@ INSERT INTO spring_boot_plus.sys_user (id, username, nickname, password, salt, r
149149``` java
150150/**
151151 * spring-boot-plus Code Generator
152+ *
152153 * @author geekidea
153- * @date 2018-11-08
154- */
155- public class CodeGenerator {
156- private static final String USER_NAME = " root" ;
157- private static final String PASSWORD = " root" ;
158- private static final String DRIVER_NAME = " com.mysql.jdbc.Driver" ;
159- private static final String DRIVER_URL = " jdbc:mysql://localhost:3306/spring_boot_plus?useUnicode=true&characterEncoding=UTF-8&useSSL=false" ;
160- // CODE...
161- // ############################ Config start ############################
162- // Module name
163- private static final String MODULE_NAME = " system" ;
164- // Author
165- private static final String AUTHOR = " geekidea" ;
166- // Table name
167- private static final String TABLE_NAME = " sys_user" ;
168- // Primary key id
169- private static final String PK_ID_COLUMN_NAME = " id" ;
170- // Generator strategy. true:All / false:SIMPLE
171- private static final boolean GENERATOR_STRATEGY = true ;
172- // Pagination list query Whether to sort. true:sort/false:non
173- private static final boolean PAGE_LIST_ORDER = false ;
174- // ############################ Config end ############################
154+ * @date 2019-10-22
155+ **/
156+ public class SpringBootPlusGenerator {
175157
176158 public static void main (String [] args ) {
177- // Run...
159+ CodeGenerator codeGenerator = new CodeGenerator ();
160+ // Common configuration
161+ // Database configuration
162+ codeGenerator
163+ .setUserName(" root" )
164+ .setPassword(" root" )
165+ .setDriverName(" com.mysql.jdbc.Driver" )
166+ .setDriverUrl(" jdbc:mysql://localhost:3306/spring_boot_plus?useUnicode=true&characterEncoding=UTF-8&useSSL=false" );
167+
168+ // Configuration package information
169+ codeGenerator
170+ .setProjectPackagePath(" io/geekidea/springbootplus" )
171+ .setParentPackage(" io.geekidea.springbootplus" );
172+
173+ // Configuration of component author, etc.
174+ codeGenerator
175+ .setModuleName(" system" )
176+ .setAuthor(" geekidea" )
177+ .setPkIdColumnName(" id" );
178+
179+ // Generation strategy
180+ codeGenerator
181+ .setGeneratorStrategy(CodeGenerator . GeneratorStrategy . ALL )
182+ .setPageListOrder(true )
183+ .setParamValidation(true );
184+
185+ // Customize which files are generated automatically
186+ codeGenerator
187+ .setGeneratorEntity(true )
188+ .setGeneratorQueryParam(true )
189+ .setGeneratorQueryVo(true );
190+
191+ // Generate business related codes
192+ codeGenerator
193+ .setGeneratorController(true )
194+ .setGeneratorService(true )
195+ .setGeneratorServiceImpl(true )
196+ .setGeneratorMapper(true )
197+ .setGeneratorMapperXml(true );
198+
199+ // Overwrite existing file or not
200+ codeGenerator. setFileOverride(true );
201+
202+ // Initialize common variables
203+ codeGenerator. init();
204+
205+ // Table array to be generated
206+ String [] tables = {
207+ " xxx" ,
208+ " yyy" ,
209+ " zzz" ,
210+ };
211+
212+ // Cycle generation
213+ for (String table : tables) {
214+ // Set the name of the table to be generated
215+ codeGenerator. setTableName(table);
216+ // Generate code
217+ codeGenerator. generator();
218+ }
219+
178220 }
221+
179222}
180223```
181224
0 commit comments