我想从列表中选择一个。列表包含五个值。**我想从列表中找到一个值。当列表中有 **importer 时,我想做点什么。我给了我的电源线,我创建了一个名为roleosuser的列表。如何检查 roleosuser 列表有进口商。当它有进口商我想做某事..我该怎么做
@RequestMapping(path = "/view/all/posted-applications/importer")
public String viewallApplicationofIMPORTER(Model model) {
Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
long userId = 0;
List <String> roleosuser;
if (principal != null && principal instanceof AuthenticatedUser) {
AuthenticatedUser auth = (AuthenticatedUser) principal;
userId = auth.getUserId();
roleosuser= auth.getUserRoles();
if(roleosuser.get(0)) {
System.out.println("importer equals "+roleosuser);
}
model.addAttribute("userID", userId);
}
return "applicationManageIMPORTER";
}
我想从我的列表中获取“IMPORTER”值。List
具有进口商和代理价值。这该怎么做?
用这个
if(roleosuser.contains("IMPORTER")) {
System.out.println("found");
// do whatever you want
}
或者
如果你想知道索引,你可以使用它
roleosuser.indexOf("IMPORTER")
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句