1
1
package com .softdev .system .generator .controller ;
2
2
3
- import com .alibaba .fastjson .JSON ;
4
3
import com .softdev .system .generator .entity .ClassInfo ;
5
4
import com .softdev .system .generator .entity .ParamInfo ;
6
5
import com .softdev .system .generator .entity .ReturnT ;
7
6
import com .softdev .system .generator .service .GeneratorService ;
8
7
import com .softdev .system .generator .util .MapUtil ;
9
8
import com .softdev .system .generator .util .TableParseUtil ;
9
+ import com .softdev .system .generator .util .ValueUtil ;
10
10
import lombok .extern .slf4j .Slf4j ;
11
11
import org .apache .commons .lang3 .StringUtils ;
12
12
import org .springframework .beans .factory .annotation .Autowired ;
13
13
import org .springframework .stereotype .Controller ;
14
14
import org .springframework .web .bind .annotation .*;
15
+ import org .springframework .web .servlet .ModelAndView ;
15
16
17
+ import java .util .Date ;
16
18
import java .util .Map ;
17
19
18
20
/**
19
- * spring boot code generator
20
- *
21
- * @author zhengk/moshow
21
+ * 代码生成控制器
22
+ * @author zhengkai.blog.csdn.net
22
23
*/
23
24
@ Controller
24
25
@ Slf4j
25
26
public class GeneratorController {
27
+ @ Autowired
28
+ private ValueUtil valueUtil ;
26
29
27
30
@ Autowired
28
31
private GeneratorService generatorService ;
29
32
30
33
@ GetMapping ("/" )
31
- public String defaultPage () {
32
- return "index" ;
34
+ public ModelAndView defaultPage () {
35
+ return new ModelAndView ( "index" ). addObject ( "value" , valueUtil ) ;
33
36
}
34
37
@ GetMapping ("/index" )
35
- public String indexPage () {
36
- return "index" ;
38
+ public ModelAndView indexPage () {
39
+ return new ModelAndView ( "index" ). addObject ( "value" , valueUtil ) ;
37
40
}
38
41
@ GetMapping ("/main" )
39
- public String mainPage () {
40
- return "main" ;
42
+ public ModelAndView mainPage () {
43
+ return new ModelAndView ( "main" ). addObject ( "value" , valueUtil ) ;
41
44
}
42
45
43
46
@ RequestMapping ("/template/all" )
@@ -49,8 +52,7 @@ public ReturnT getAllTemplates() throws Exception {
49
52
@ PostMapping ("/code/generate" )
50
53
@ ResponseBody
51
54
public ReturnT generateCode (@ RequestBody ParamInfo paramInfo ) throws Exception {
52
-
53
- log .info (JSON .toJSONString (paramInfo ));
55
+ //log.info(JSON.toJSONString(paramInfo.getOptions()));
54
56
if (StringUtils .isEmpty (paramInfo .getTableSql ())) {
55
57
return ReturnT .error ("表结构信息为空" );
56
58
}
@@ -82,7 +84,7 @@ public ReturnT generateCode(@RequestBody ParamInfo paramInfo) throws Exception {
82
84
83
85
//3.generate the code by freemarker templates with parameters . Freemarker根据参数和模板生成代码
84
86
Map <String , String > result = generatorService .getResultByParams (paramInfo .getOptions ());
85
-
87
+ log . info ( "table:{} - time:{} " , MapUtil . getString ( result , "tableName" ), new Date ());
86
88
return ReturnT .ok ().put ("outputJson" ,result );
87
89
}
88
90
0 commit comments