首页 > 编程语言 > 详细

SpringMVC的RestFul 风格

时间:2021-07-13 20:13:53      阅读:11      评论:0      收藏:0      [点我收藏+]

让URL地址变的更简介、有层次、安全

@GetMapping
@PostMapping
@PutMapping
@DeleteMapping
@PatchMapping

@GetMapping 是一个组合注解,平时使用的会比较多!

@Controller
public class RestFulController {
    //原来的:http://localhost:8080/add?a=1&b=2
    //RestFul:http://localhost:8080/add/1/2

//    @RequestMapping(value ="/add/{a}/{b}",method = RequestMethod.POST)//功能与下相同
    @PostMapping("/add/{a}/{b}")
    public String test1(@PathVariable int a, @PathVariable String b, Model model){
        String res = a + b;
        model.addAttribute("msg","结果1POST为:"+res);
        return "test";
    }
    @GetMapping("/add/{a}/{b}")
    public String test2(@PathVariable int a, @PathVariable String b, Model model){
        String res = a + b;
        model.addAttribute("msg","结果2GET为:"+res);
        return "test";
    }
}

技术分享图片
随便写一个a.jsp:

<body>
<form action="/add/1/5" method="post">
    <input type="submit">
</form>
</body>

提交后如下图:
技术分享图片

SpringMVC的RestFul 风格

原文:https://www.cnblogs.com/xudong-he/p/15007646.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!