44import jakarta .servlet .http .HttpServletRequest ;
55import org .ma5d .javamock .dto .SaveParam ;
66import org .ma5d .javamock .service .JavaMockServiceImpl ;
7- import org .springframework .beans .factory .annotation .Autowired ;
87import org .springframework .stereotype .Controller ;
98import org .springframework .ui .Model ;
109import org .springframework .web .bind .annotation .*;
1514@ Controller
1615public class MockController {
1716 @ Resource
18- JavaMockServiceImpl javaMockService ;
19- @ Autowired
20- private JavaMockServiceImpl javaMockServiceImpl ;
17+ private JavaMockServiceImpl javaMockService ;
2118
19+ // region 查
2220 @ GetMapping ("/" )
2321 public String index () {
2422 return "redirect:/index" ;
@@ -30,26 +28,47 @@ public String index(Model model) throws SQLException {
3028 model .addAttribute ("saveParams" , saveParams );
3129 return "index" ;
3230 }
31+ // endregion
32+
33+ // region 增
34+ @ GetMapping ("/new" )
35+ public String newItem (Model model ) {
36+ SaveParam saveParam = new SaveParam ();
37+ model .addAttribute ("saveParam" , saveParam );
38+ return "detail" ;
39+ }
3340
3441 @ PostMapping ("/save" )
3542 public String configure (@ ModelAttribute ("saveParam" ) SaveParam saveParam ) throws SQLException {
3643 javaMockService .saveConfig (saveParam );
3744 return "redirect:/" ;
3845 }
46+ // endregion
3947
48+ // region 删
49+ @ GetMapping ("/delete/{id}" )
50+ public String delete (@ PathVariable String id ) throws SQLException {
51+ javaMockService .deleteByTimeStamp (id );
52+ return "redirect:/" ;
53+ }
54+ // endregion
55+
56+ // region 改
4057 @ GetMapping ("/detail/{timeStamp}" )
4158 public String detail (@ PathVariable String timeStamp , Model model ) throws SQLException {
4259 SaveParam saveParam = javaMockService .queryLine (timeStamp );
4360 model .addAttribute ("saveParam" , saveParam );
4461 return "detail" ;
4562 }
63+ // endregion
4664
65+ // region 主要逻辑
4766 @ ResponseBody
4867 @ GetMapping ("/p/**" )
4968 public String proxyGet (HttpServletRequest request ) throws SQLException {
5069 String requestURI = request .getRequestURI ();
5170 String pathWithParam = "/" + requestURI .split ("/p/" )[1 ];
52- SaveParam saveParam = javaMockServiceImpl .getSaveParamByPathWithParam (pathWithParam );
71+ SaveParam saveParam = javaMockService .getSaveParamByPathWithParam (pathWithParam );
5372 return saveParam .getResponse ();
5473 }
5574
@@ -58,8 +77,8 @@ public String proxyGet(HttpServletRequest request) throws SQLException {
5877 public String proxyPost (HttpServletRequest request ) throws SQLException {
5978 String requestURI = request .getRequestURI ();
6079 String pathWithParam = "/" + requestURI .split ("/p/" )[1 ];
61- SaveParam saveParam = javaMockServiceImpl .getSaveParamByPathWithParam (pathWithParam );
80+ SaveParam saveParam = javaMockService .getSaveParamByPathWithParam (pathWithParam );
6281 return saveParam .getResponse ();
6382 }
64-
83+ // endregion
6584}
0 commit comments