【SpringMVC从看懂到看开】3 - RESTful风格

6 RESTful风格

REST,Representational State Transfer,指的是一组架构约束条件和原则。满足这些约束条件和原则的应用程序或设计就是 RESTful。
RESTful风格是Web应用程序的设计风格和开发方式,它不是一种规范,也不是一种标准,你也可以不使用,但使用RESTful风格的软件会变得更加简洁、更有层次、更易于实现缓存机制。

6.1 不使用RESTful风格

@Controller
@RequestMapping(value = "/helloController")
public class HelloController {
    @RequestMapping("restful")
    public String RESTfulTest(int a, int b, Model model){
        model.addAttribute("result",a+b);
        return "RESTfulTest";
    }
}

在这里插入图片描述

6.2 使用RESTful风格

@Controller
@RequestMapping(value = "/helloController")
public class HelloController {
    @RequestMapping("/h1")
    public String sayHello(Model model){
        model.addAttribute("msg","Hello Spring MVC Annotation");
        return "hello";
    }

    @RequestMapping("restful/{a}/{b}")
    public String RESTfulTest(@PathVariable int a,@PathVariable int b, Model model){
        model.addAttribute("result",a+b);
        return "RESTfulTest";
    }
}

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/Cap220590/article/details/107378951