a0be14466b24a8792d62086186a9d3be948bb142
code-gen.md
| ... | ... | @@ -2,58 +2,9 @@ |
| 2 | 2 | |
| 3 | 3 | 代码生成器引入了更加灵活和高效的 builder 模式,使得开发者能够快速生成符合需求的代码,同时保持代码的优雅和整洁。这个新特性旨在进一步提升开发效率,减少重复劳动,让开发者能够更加专注于业务逻辑的实现。 |
| 4 | 4 | |
| 5 | - |
|
| 5 | +代码实例 |
|
| 6 | 6 | ``` |
| 7 | -F |
|
| 8 | -astAutoGenerator.create(ConfigUtils.load("dbcp.properties")) |
|
| 9 | -.dataSourceConfig(builder -> { |
|
| 10 | -builder.databaseQueryClass(DefaultQuery.class); |
|
| 11 | -}) |
|
| 12 | -.globalConfig(builder -> { |
|
| 13 | -builder.outputDir("C:\\Users\\29662\\Documents\\dynamic-group\\src\\main\\java\\com\\sie\\snest\\dynamic\\group\\model\\"); |
|
| 14 | -builder.author("mijiuye"); |
|
| 15 | -builder.jsonFilePath("C:\\Users\\29662\\IdeaProjects\\sie-snest\\sie-snest-code-generator\\src\\main\\java\\com\\sie\\snest\\engine\\generator\\app.json"); |
|
| 16 | -}) |
|
| 17 | -.packageConfig(builder -> { |
|
| 18 | -builder.parent("com.sie.snest.dynamic.group"); |
|
| 19 | -builder.version("1.0.0"); |
|
| 20 | -}) |
|
| 21 | -.templateConfig(builder -> builder.classzz(true)) |
|
| 22 | -.compilerConfig(builder -> { |
|
| 23 | - |
|
| 24 | -String sourceDir = "C:\\Users\\29662\\Documents\\dynamic-group\\"; |
|
| 25 | -String libDir = "C:\\Users\\29662\\Documents\\dynamic-group\\target\\lib\\"; |
|
| 26 | -String outputLocation = "C:\\Users\\29662\\Documents\\dynamic-group\\src\\main\\java\\"; |
|
| 27 | - |
|
| 28 | - |
|
| 29 | -List<String> filenames = null; |
|
| 30 | -try { |
|
| 31 | -filenames = FileUtils.getFileNames(new File(libDir), "**/*.jar", null, false, true); |
|
| 32 | -} catch (IOException e) { |
|
| 33 | -throw new RuntimeException(e); |
|
| 34 | -} |
|
| 35 | -Collections.sort(filenames); |
|
| 36 | -List<String> classpathEntries = new ArrayList<>(); |
|
| 37 | -for (String filename : filenames) { |
|
| 38 | -classpathEntries.add(libDir + filename); |
|
| 39 | -} |
|
| 40 | - |
|
| 41 | 7 | |
| 42 | -builder.setClasspathEntries(classpathEntries); |
|
| 43 | -builder.addSourceLocation(sourceDir); |
|
| 44 | -builder.setOutputLocation(outputLocation); |
|
| 45 | -try { |
|
| 46 | -FileUtils.deleteDirectory(outputLocation); |
|
| 47 | -} catch (IOException e) { |
|
| 48 | -throw new RuntimeException(e); |
|
| 49 | -} |
|
| 50 | -// compilerConfig.addInclude( filename ); |
|
| 51 | -//compilerConfig.setSourceFiles(files); |
|
| 52 | -builder.setTargetVersion("1.8"); |
|
| 53 | -builder.setSourceVersion("1.8"); |
|
| 54 | -}) |
|
| 55 | -.templateEngine(new FreemarkerTemplateEngine()) |
|
| 56 | -.execute(); |
|
| 57 | 8 | |
| 58 | 9 | ``` |
| 59 | 10 |