sur*_*esh 38 jax-rs spring-mvc restful-url path-parameter
据我所知,两者都有同样的目的.除了@PathVariable来自Spring MVC并@PathParam来自JAX-RS 的事实.有什么见解吗?
Pre*_*raj 25
@PathVariable和@PathParam都用于从URI模板访问参数
区别:
Omk*_*kar 18
PathParam:
将URI参数值分配给方法参数.在春天,它是@RequestParam.
例如.,
http://localhost:8080/books?isbn=1234
@GetMapping("/books/")
public Book getBookDetails(@RequestParam("isbn") String isbn) {
Run Code Online (Sandbox Code Playgroud)
PathVariable:
将URI占位符值分配给方法参数.
例如.,
http://localhost:8080/books/1234
@GetMapping("/books/{isbn}")
public Book getBook(@PathVariable("isbn") String isbn) {
Run Code Online (Sandbox Code Playgroud)
@PathParam是一个参数注释,它允许您将变量URI路径片段映射到方法调用中.
@Path("/library")
public class Library {
@GET
@Path("/book/{isbn}")
public String getBook(@PathParam("isbn") String id) {
// search my database and get a string representation and return it
}
}
Run Code Online (Sandbox Code Playgroud)
有关详细信息:JBoss DOCS
在Spring MVC中,您可以在方法参数上使用@PathVariable注释将其绑定到URI模板变量的值以获取更多详细信息:SPRING DOCS
| 归档时间: |
|
| 查看次数: |
57890 次 |
| 最近记录: |