RestFul风格讲解

RestFul风格讲解_第1张图片

以前是localhost:8080/user?method=add&uid=1;

RestFul风格是以/接上的 localhost:8080/user/马云/6562

RestFul风格讲解_第2张图片

 RestFul风格讲解_第3张图片

 RestFul风格讲解_第4张图片

 RestFul风格讲解_第5张图片

RestFul风格讲解_第6张图片 

RestFul风格讲解_第7张图片 

 

package com.qf.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

@Controller
public class RestFulController {
//    @RequestMapping(value = "/add/{a}/{b}",method = RequestMethod.GET)
//    @RequestMapping(value = "/add/{a}/{b}",method = RequestMethod.DELETE)

    //安全

    // 原来的:http://localhost:8080/add?a=1&b=2
    // RestFul的:http://localhost:8080/add?a=1&b=2 @PathVariable路径绑定
//    @GetMapping("/add/{a}/{b}")
    @PostMapping("/add/{a}/{b}")
    public String test1(@PathVariable int a,@PathVariable String b, Model model){
        String res=a+b;
        model.addAttribute("msg","结果为:"+res);
        return "test";
    }
    @GetMapping("/add/{a}/{b}")
    public String test2(@PathVariable int a,@PathVariable int b, Model model){
        int res=a+b;
        model.addAttribute("msg","结果为:"+res);
        return "test";
    }

}
<%--
  Created by IntelliJ IDEA.
  User: 蒋铭基
  Date: 2023/7/15
  Time: 15:24
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>


    Title


RestFul风格讲解_第8张图片

 

你可能感兴趣的:(SpringMVC,restful,后端)