- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有 2 个不同的 URL:
GET /stuff/{id} (where id is an Integer)
GET /stuff/foo?bar={someValue} (foo is not an Integer, it is a hard coded String)
当调用/stuff/foo&bar=someValue
时,出现以下错误:
Failed executing GET /stuff/foo&bar=someValue
...
Caused by: java.lang.NumberFormatException: For input string: "foo&bar=someValue"
代码是:
@GET
@Path("/stuff/{id}")
public Response getById(@PathParam("id") int id) {
// code
}
@GET
@Path("/stuff/foo")
public Response foo(@QueryParam("bar") String bar) {
// code
}
我正在使用 RESTEasy如果可能的话,我想保留我的 URL。显然,RESTEasy 只是在应该使用 foo 方法的地方尝试了 getById 方法。
我怎样才能在 RESTEasy 中完成这项工作? (如果没有关于 RESTEasy 限制的详细解释,“更改您的 URL”不是答案)。我尝试(确定)将 foo 代码放在 getById 之前,但我有同样的错误(当然)。
声明的 URL 之间是否有优先级概念?
请注意:我已经在另一个框架 (python-flask) 中实现了这种 URL,它工作得很好:你只需要小心声明/stuff/foo before/stuff/{id}(在更通用的案例之前的特定案例)。
编辑:我刚刚犯了一个愚蠢的错误!我正在调用 /stuff/foo&bar=someValue
,而我应该调用 /stuff/foo?bar=someValue
。感谢@Scobal 指出!
最佳答案
您正在调用 GET/stuff/foo&bar=someValue
您应该调用 GET/stuff/foo?bar=someValue
RESTEasy 正在尝试将 foo&bar=someValue
解析为 {id}
字段。
我无法给你关于 RESTEasy URL 优先级的答案,但你可以这样做:
@GET
@Path("/stuff/{id}")
public Response getById(@PathParam("id") String id, @QueryParam("bar") String bar) {
try {
int intId = Integer.parseInt(id);
// do int id things
} catch(NumberFormatException e) {
// do foo + bar things
}
}
关于java - 两个 URL 之间的容易混淆,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22170584/
所以我试图让(例如)输入一些值:1 -2 -3 2 5正数的数量是 5 负数的数量是 -3总计为 3 平均值为 0.6我想让它像这样,但是当我运行它时,它不起作用哪一部分是错误的??? import
我编写了一个使用 OpenCV 的 cvCalcOpticalFlowLK 的程序。它在低分辨率网络摄像头输入上表现良好,但我需要在全高清流上运行它,并在对每一帧进行光流分析后进行重要的其他计算。处理
如果我有一个 ruby 脚本 Daemon,顾名思义,它作为守护进程运行,监视系统的各个部分并能够执行需要身份验证的命令,例如更改权限,是否存在一个简单的方法来拥有第二个 ruby 脚本,比如
我们有一个基于 Ant 和 Ivy 的构建管理系统,它基本上由一个共享的 ant 文件和一组围绕目录结构的约定组成。 我试图克服的一个障碍是相当常见的“递归发布”情况。比如说,我们有 5 个内部代码模
我在嵌入式 Linux 环境中遇到了问题。尝试确定它是否可以由应用程序引起。应用程序导致内核崩溃/锁定或终止 init 有多容易? 最佳答案 非根应用程序应该不可能影响任何一个。 以 root 身份运
我目前正在尝试学习 Nim(进展缓慢 - 无法投入太多时间)。另一方面,为了获得一些工作代码,我想对我正在 ruby 中开发的 Nim 应用程序的各个部分进行原型(prototype)设计。 由于
我是一名优秀的程序员,十分优秀!