网址的类型为:http://localhost:8080/mdnd_myshelfService_V1.0/myshelf/authenticateUserAndGetHospitalDetails?username=85010352:password=asddddsad2342#$
在 Controller 类中,将使用以下方法来验证并获取用户名的医院数据。
@GET
@Path("/authenticateUserAndGetHospitalDetails")
//@path is not complete should be something like /authenticateUserAndGetHospitalDetails?{username}:{password}
@Produces(MediaType.APPLICATION_JSON)
public Hospital getAllHospitalData(@PathParam("userId") String userId) {
log.error("in getAllHospitalData.. " + userId + " | " );
//need to get parameter values of username and password from url
}
最佳答案
您可以使用@QueryParam
注释。
@GET
@Path("/authenticateUserAndGetHospitalDetails")
@Produces(MediaType.APPLICATION_JSON)
public Hospital getAllHospitalData(@PathParam("userId") String userId, @QueryParam("password") String password, @QueryParam("username") String username) {
...
这会将 url 参数绑定(bind)到其相应的方法参数。网址如
http://localhost:8080/mdnd_myshelfService_V1.0/myshelf/authenticateUserAndGetHospitalDetails?username=85010352:password=asddddsad2342#$
假设您的网络服务器接受 :
作为参数分隔符,则变量 username
将具有值 85010352
和变量 密码
的值为asddddsad2342#$
。
关于java - 使用 hibernate 从 URL 获取参数值而不使用请求对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18574272/