import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
@Controller
@Path("/path")
public class PathController {
// http://localhost:8078/api/practiceDemo/v1/path/query1 结果: query success!!
@Path("/query1")
@GET
@Produces(MediaType.TEXT_PLAIN)
public String query1(String name) {
return name + " query success!!";
}
// http://localhost:8078/api/practiceDemo/v1/path/query2/123 结果:123 query success!!
@Path("/query2/{name}")
@GET
@Produces(MediaType.TEXT_PLAIN)
public String query2(@PathParam(value = "name") String name) {
return name + " query success!!";
}
//http://localhost:8078/api/practiceDemo/v1/path/query4?name=123 结果:123 query success!!
@Path("/query4")
@GET
@Produces(MediaType.TEXT_PLAIN)
public String query4(@QueryParam(value = "name") String name) {
return name + " query success!!";
}
}
@Path=====使用====@PathParam、@PathVariable和@QueryParam
最新推荐文章于 2022-01-04 15:54:33 发布