zoukankan      html  css  js  c++  java
  • RESTful风格

    RESTful风格

    传统方式

    @RequestMapping("/add")
    public String test1(int a, int b, Model model) {
    	int res = a + b;
        model.addAttribute("msg", "a + b = " + res);
        return "test";
    }
    

    url: http://localhost:8080/r/add?a=5&b=2

    页面输出:a + b = 7

    RESTful风格

    @RequestMapping("/add/{a}/{b}")
    public String test1(@PathVariable int a, @PathVariable int b, Model model) {
        int res = a + b;
        model.addAttribute("msg", "a + b = " + res);
        return "test";
    }
    

    url:http://localhost:8080/r/add/5/2

    页面输出:a + b = 7

    指定方法

    //@RequestMapping(value = "/add/{a}/{b}", method = RequestMethod.GET)
    @GetMapping("/add/{a}/{b}")//效果同上
    public String test1(@PathVariable int a, @PathVariable String b, Model model) {
        String res = a + b;
        model.addAttribute("msg", "ab = " + res);
        return "test";
    }
    @PostMapping("/add/{a}/{b}")//实现url复用
    public String test2(@PathVariable int a, @PathVariable String b, Model model) {
        String res = a + b;
        model.addAttribute("msg", "ab = " + res);
        return "test";
    }
    

    不同方法用不同的注释:

    • @GetMapping
    • @PostMapping
    • @PutMapping
    • @DeleteMapping
    • @PatchMapping
  • 相关阅读:
    Dialog对话框
    Intent的七大属性
    Activity启动模式
    Android知识体系
    Activity生命周期
    Intent实现页面跳转和传值
    Android超链接
    上传文件
    XMLSAX解析
    XmlPull
  • 原文地址:https://www.cnblogs.com/pinked/p/12227373.html
Copyright © 2011-2022 走看看