簡體   English   中英

我如何在春季使用HandlerInterceptor讀取@Pathvariable名稱和值?

[英]how can i read @Pathvariable name and value using HandlerInterceptor in spring?

我的代碼是:

@RequestMapping(value = "productDescription/{productId}/{competitorList}", method = RequestMethod.GET)
@ResponseBody
public ProductDescription getProductDescription(
        @PathVariable String productId, @PathVariable String competitorList) {
    return service.getProductDescription(productId, competitorList);
}

在postHandler方法中使用HttpServletRequest請求,我想讀取路徑變量的名稱和值。

如果我使用@RequestParam而不是@Pathvariable,則可以使用request.getParameterMap()方法獲取參數名稱和值。

嘗試這個:

@RequestMapping(value = "productDescription/{productId}/{competitorList}", method = RequestMethod.GET)
@ResponseBody
public ProductDescription getProductDescription(@PathVariable("productId") String productId, @PathVariable("competitorList") String competitorList) {
    return service.getProductDescription(productId, competitorList);
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM