@Path=====使用====@PathParam、@PathVariable和@QueryParam

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!!";
    }
}

猜你喜欢

转载自blog.csdn.net/qq_27827469/article/details/82184120