java - 使用 hibernate 从 URL 获取参数值而不使用请求对象?

标签 java hibernate

网址的类型为: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/

相关文章:

java - 表达式的非法开始 - for 循环

java - final 变量和 lazySet 实现都需要 LoadStore 和 StoreStore 吗?

java - 如何制作JButton图标透明,文字不透明?

java - Hibernate 空间索引注释

mysql - 如何将hibernate查询转换为sql

Hibernate 自定义 SQL 查询与连接 - 避免返回数组列表

java - 不相关实体的 HQL 左连接

java - 主线程退出的多线程,其他线程是否有可能无限运行

mysql - 使用 Spring、Hibernate 和 MySQL 编码 hell

java - JSP内容显示在浏览器上