百度百科介绍
简单应用
Controller层
package com.harris.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
public class RestfulController {
@RequestMapping(value = "/add/{a}/{b}",method = RequestMethod.GET)
public String test(@PathVariable int a,@PathVariable int b, Model model){
int res= a+b;
model.addAttribute("msg","结果为:"+res);
return "hello";
}
}
通过对要传入的变量添加注解@PathVariable
使得可以通过url以/的形式传参。