Controller
- @Controller 处理http请求,返回模版
- @RestController 处理http请求,返回JSON
等同于 @Controller +
- 处理url映射
@RestController@RequestMapping("/a")public class HelloController {@Autowiredprivate LimitConfig limitConfig;// 请求url -> http://localhost:8081/luckymoney/a/hello/100// 返回 -> id100@GetMapping("/hello/{id}")public String sayId(@PathVariable("id") Integer id) {return "id" + id;}// 请求url -> http://localhost:8081/luckymoney/a/hello?id=100// 返回 -> id100@GetMapping("/hello")public String sayNum(@RequestParam("id") Integer id) {return "id" + id;}@PostMapping("/h2")public String sayh() {return "minmoney: " + limitConfig.getMinMoney() + " reson: " + limitConfig.getDescription();}}
