关于REST和RESTful的说明请移步至:怎样用通俗的语言解释REST,以及RESTful?
其实我自己也不是十分的理解,只是今天学SpringBoot时看到有个标着REST风格的简单例子,就记录一下。
代码如下:
1 @RestController 2 @EnableAutoConfiguration 3 public class Controller { 4
5 //REST风格?
6 @RequestMapping("/index/{msg}") // 7 public String Hello(@PathVariable String msg) { 8 return "你好,"+msg; 9 } 10
11 public static void main(String[] args) { 12 // TODO Auto-generated method stub
13 SpringApplication.run(Controller.class, args); 14
15 } 16
17 }
然后实现的效果如下: