@PathVariable

@PathVariable 映射 URL 绑定的占位符
带占位符的 URL 是 Spring3.0 新增的功能,该功能在SpringMVC 向 REST 目标挺进发展过程中具有里程碑的意义通过 @PathVariable 可以将 URL 中占位符参数绑定到控制器处理方法的入参中:URL 中的 {xxx} 占位符可以通过@PathVariable(“xxx“)
绑定到操作方法的入参中。

实例: SpringMVCTest.java
//@PathVariable可以用来映射URL中的占位符到目标方法的参数中@RequestMapping("/testPathVariable/{id}")    public String testPathVariable(@PathVariable("id") Integer id)    {        System.out.println("testPathVariable:"+id);        return SUCCESS;    }

index.jsp
<a href="springmvc/testPathVariable/1">testPathVariable</a>

---------------------

本文来自 Alan_ckc 的CSDN 博客 ,全文地址请点击:https://blog.csdn.net/ckc_666/article/details/79239974?utm_source=copy

猜你喜欢

转载自blog.csdn.net/qq_40680694/article/details/82852292