
以前是localhost:8080/user?method=add&uid=1;
RestFul风格是以/接上的 localhost:8080/user/马云/6562

 
 
 
 
 
 
 
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" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<form action="/add/1/2" method="get">
    <input type="submit">
</form>
</body>
</html>




















