2011-11-30 31 views
2

我使用遊戲框架,我需要檢查用戶與@secure標註權限,但我在這裏得到了一個問題:如何傳遞請求參數到Java註釋

@secure(UID=???) 
public static void removeFavorite(Long storyId,Long userId){ 

} 

任何一個可以告訴我如何在註釋中將「userId」參數傳遞給「UID」?

PS:「userId」參數在請求範圍內。

非常感謝!

回答

2

AFAIK您不能在運行時更改註釋(至少不是沒有動態代碼生成)。此外,註釋是靜態的,即它們適用於類或類成員(字段,方法等),並且不能在每個實例中更改。因此,您無法將userId傳遞給該註釋。

我不知道t know what @secure does, but generally, you'd read the annotation at runtime and optionally check its static parameters and if those checks succeed you'd read the userId`參數並在出現該註釋時做適當的操作。