RestFul风格
RestFul就是一个容易定位和对资源操作的一种风格。它更高效,更安全,更简洁
1、方式一
使用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"; } }
@PathVariable作用就是在请求的url中获取对应的参数
结果
方式二(最常用的方法)
使用组合注解
@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"; }
结果
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 字符编码:从基础到乱码解决
· 提示词工程——AI应用必不可少的技术