SpringMVC中@PathVariable(value="id")

@Controller
@RequestMapping(value="/hello")     // 在类上加[@RequestMapping("/hello")]注解,请求路径就会变成
                            // [http://localhost:8080/SpringHelloWorld/hello/world]
public class Helloworld {

    @RequestMapping(value="/world/{id}")
    public String Helloworld(@PathVariable(value="id") Integer id) {
        System.out.println("开始处理页面请求..." + id);
        return "success";
    }
}

运行结果:

{id}相当于占位符,根据URL传进来的参数,传递给integer id;

猜你喜欢

转载自www.cnblogs.com/batj/p/9206478.html