1 回答

TA貢獻1797條經驗 獲得超4個贊
為了匹配您的描述中的 URL,最好的辦法是轉義月、日和年等不同的日期部分。然后在方法內部,您可以將它們拼湊起來成為一個 Date 對象。
要將它們全部捕獲為一種日期類型,將針對 URL 結構運行,在這種情況下,它無法區分日期中的“斜線”與區分不同 URL 參數的“斜線”之間的區別。如果您不想為日期切換到 ISO-8601 表示形式并且不想將斜杠 %-encode 為 %2F 或使用查詢字符串等。
這樣的事情應該有效:
@GET
@Path("/dd/{sp}/{rpt}/{ter}/{month}/{day}/{year}/{grant}/{refresh}")
@Produces(MediaType.APPLICATION_JSON)
public List<ReportPeriodBean> getApprovals(@PathParam("sp") String sp,
@PathParam("rpt") String rpt,
@PathParam("ter") String ter,
@PathParam("month") int month,
@PathParam("day") int day,
@PathParam("year") int year,
@PathParam("grant") String grant,
@PathParam("refresh") boolean refresh) {
LocalDate date = LocalDate.of(year, month, day);
// Now use the date however you like
}
這將使您能夠將您的 URL 保留在似乎首選的語法中:
rs/Service/Store/Grantor/122/5801/DUE/10/30/2017/grantValue/true?request.preventCache=1562353357306
添加回答
舉報