2015-09-25 88 views
0

登錄後返回根/索引請求映射空列表我有一個在登錄使用我的應用程序的索引頁以下請求映射。我有一個說法解析器我Person類型的給我我當前登錄的用戶。雖然在調試運行時,我可以檢查currentUser,看到了用戶的權限,但是當它添加到模型所產生的authorities集合總是空的。所以,我有種抓我的頭,爲什麼。我使用JPA來從數據庫中獲取用戶的信息。獲取用戶權限列表中

@RequestMapping(value = "/", method = RequestMethod.GET) 
public String index(Model model, Person currentUser) { 
    Collection<String> authorities = currentUser.getAuthorities().stream().map(GrantedApplication::getAuthority).collect(Collectors.toList()); 
    model.addAttribute("authorities", authorities); 
    return "index"; 
} 

回答

0

所以原來我Person類型,我只需要設置取躍躍欲試的機構和它的作品...

@OneToMany 
@JoinColumn(name = "UACODE", referencedColumnName = "USRCODE") 
private Collection<GrantedApplication> authorities; 

之前

@OneToMany(fetch = FetchType.EAGER) 
@JoinColumn(name = "UACODE", referencedColumnName = "USRCODE") 
private Collection<GrantedApplication> authorities;