亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

路徑中的日期會誤導請求 URI

路徑中的日期會誤導請求 URI

慕桂英3389331 2023-03-09 13:37:48
我有一個日期格式為“無法加載 rs/Service/Store/Grantor/122/5801/DUE/10/30/2017//true?request.preventCache=1562353357306 狀態:404”的 URL,其中 10 /30/2017 是它擁有的 Java 代碼中的一個日期@GET@Path("/dd/{sp}/{rpt}/{ter}/{date}/{grant}/{refresh}")@Produces(MediaType.APPLICATION_JSON)public List<ReportPeriodBean> getApprovals(@PathParam("sp") String sp,        @PathParam("rpt") String rpt, @PathParam("ter") String ter,        @PathParam("date") String date,        @PathParam("grant") String grant, @PathParam("refresh") boolean refresh) throws Exception {我應該如何讓我的 URL 以正確的日期格式出現,并允許控制器處理其余的事情,無論如何在春天?
查看完整描述

1 回答

?
繁星coding

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


查看完整回答
反對 回復 2023-03-09
  • 1 回答
  • 0 關注
  • 70 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號