RestFul就是一个容易定位和对资源操作的一种风格。它更高效,更安全,更简洁
使用RequestMappering去实现
在方法上实现
@Controller public class RestFul { @RequestMapping(value = "/add/{a}/{b}",method = RequestMethod.GET) //@RequestMapping(path = "/add/{a}/{b}",method = RequestMethod.GET) public String test1(@PathVariable int a ,@PathVariable int b, Model model){ model.addAttribute("msg","结果为"+(a+b)); return "test"; } }
结果
使用组合注解
@GetMapping
@PostMapping
@PutMapping
@DeleteMapping
@PatchMapping
@GetMapping("/add/{a}/{b}") public String test2(@PathVariable int a ,@PathVariable int b, Model model){ model.addAttribute("msg","结果为test"+(a+b)); return "test"; }
结果