Controller

  1. @Controller 处理http请求,返回模版
  2. @RestController 处理http请求,返回JSON

等同于 @Controller +

  1. 处理url映射
  1. @RestController
  2. @RequestMapping("/a")
  3. public class HelloController {
  4. @Autowired
  5. private LimitConfig limitConfig;
  6. // 请求url -> http://localhost:8081/luckymoney/a/hello/100
  7. // 返回 -> id100
  8. @GetMapping("/hello/{id}")
  9. public String sayId(@PathVariable("id") Integer id) {
  10. return "id" + id;
  11. }
  12. // 请求url -> http://localhost:8081/luckymoney/a/hello?id=100
  13. // 返回 -> id100
  14. @GetMapping("/hello")
  15. public String sayNum(@RequestParam("id") Integer id) {
  16. return "id" + id;
  17. }
  18. @PostMapping("/h2")
  19. public String sayh() {
  20. return "minmoney: " + limitConfig.getMinMoney() + " reson: " + limitConfig.getDescription();
  21. }
  22. }