|
| 1 | +package com.codingapi.springboot.example.controller; |
| 2 | + |
| 3 | +import com.codingapi.springboot.example.infrastructure.jpa.entity.NodeEntity; |
| 4 | +import com.codingapi.springboot.fast.mapping.MvcMappingRegister; |
| 5 | +import com.codingapi.springboot.fast.mapping.SQLMapping; |
| 6 | +import com.codingapi.springboot.fast.mapping.ScriptMapping; |
| 7 | +import lombok.AllArgsConstructor; |
| 8 | +import org.springframework.web.bind.annotation.PostMapping; |
| 9 | +import org.springframework.web.bind.annotation.RequestMapping; |
| 10 | +import org.springframework.web.bind.annotation.RequestMethod; |
| 11 | +import org.springframework.web.bind.annotation.RestController; |
| 12 | + |
| 13 | +@RestController |
| 14 | +@RequestMapping("/open/mvc") |
| 15 | +@AllArgsConstructor |
| 16 | +public class MvcController { |
| 17 | + |
| 18 | + |
| 19 | + private final MvcMappingRegister mvcMappingRegister; |
| 20 | + |
| 21 | + |
| 22 | + @PostMapping("/hqlTest") |
| 23 | + public void hqlTest() { |
| 24 | + String mapping = "/open/test/hqlTest"; |
| 25 | + RequestMethod requestMethod = RequestMethod.GET; |
| 26 | + SQLMapping sqlMapping = SQLMapping.hqlMapping(mapping, requestMethod, |
| 27 | + "from NodeEntity", NodeEntity.class); |
| 28 | + mvcMappingRegister.addMapping(sqlMapping); |
| 29 | + } |
| 30 | + |
| 31 | + |
| 32 | + @PostMapping("/sqlTest") |
| 33 | + public void sqlTest() { |
| 34 | + String mapping = "/open/test/sqlTest"; |
| 35 | + RequestMethod requestMethod = RequestMethod.GET; |
| 36 | + SQLMapping sqlMapping = SQLMapping.jdbcMapMapping(mapping, requestMethod, |
| 37 | + "select * from t_node"); |
| 38 | + mvcMappingRegister.addMapping(sqlMapping); |
| 39 | + } |
| 40 | + |
| 41 | + |
| 42 | + @PostMapping("/scriptTest") |
| 43 | + public void scriptTest() { |
| 44 | + String mapping = "/open/test/scriptTest"; |
| 45 | + RequestMethod requestMethod = RequestMethod.GET; |
| 46 | + String script = """ |
| 47 | + var sql = "select * from t_node"; |
| 48 | + var result = $jdbc.queryForList(sql); |
| 49 | + return result; |
| 50 | + """; |
| 51 | + |
| 52 | + ScriptMapping scriptMapping = new ScriptMapping(mapping,requestMethod,script); |
| 53 | + mvcMappingRegister.addMapping(scriptMapping); |
| 54 | + } |
| 55 | + |
| 56 | + @PostMapping("/removeSqlTest") |
| 57 | + public void removeSqlTest() { |
| 58 | + String mapping = "/open/test/sqlTest"; |
| 59 | + RequestMethod requestMethod = RequestMethod.GET; |
| 60 | + mvcMappingRegister.removeMapping(mapping,requestMethod); |
| 61 | + } |
| 62 | + |
| 63 | + |
| 64 | + @PostMapping("/removeHqlTest") |
| 65 | + public void removeHqlTest() { |
| 66 | + String mapping = "/open/test/hqlTest"; |
| 67 | + RequestMethod requestMethod = RequestMethod.GET; |
| 68 | + mvcMappingRegister.removeMapping(mapping,requestMethod); |
| 69 | + } |
| 70 | + |
| 71 | + @PostMapping("/removeScriptTest") |
| 72 | + public void removeScriptTest() { |
| 73 | + String mapping = "/open/test/scriptTest"; |
| 74 | + RequestMethod requestMethod = RequestMethod.GET; |
| 75 | + mvcMappingRegister.removeMapping(mapping,requestMethod); |
| 76 | + } |
| 77 | + |
| 78 | +} |
0 commit comments