restful 风格

发布时间 2023-08-22 20:19:40作者: MaoShine

代码示例:


import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
public class Test1 {
    @RequestMapping("/t1/{name}")
    public String test1(@PathVariable String name, Model model){
        model.addAttribute("msg","name: "+name);
        return "test";
    }
    @RequestMapping("/t2/{p1}/{p2}")
    public String test2(@PathVariable int p1,@PathVariable int p2, Model model){
        model.addAttribute("msg","Result: "+ (p1+p2));
        return "test";
    }
}