我想在rolePriority中找到最小数字。如何在for循环中获得最小数字。
UserRole.java
<?php
header('Content-Type: image/jpeg');
$src = "image path goes here".$_GET['imagename'];
readfile($src);
unlink("image path goes here".$_GET['imagename']);
?>
RoleAction.java
public class UserRole implements Serializable{ private Integer id; private User user; private Role role;
public class RoleAction implements Serializable{
private Integer id;
private Role role;
private Action action;
}
答案 0 :(得分:1)
如果要在任何用户角色中找到最小角色优先级,则可以尝试以下操作:
int minPriority = -1;
for (UserRole userRole : userRoles) {
dbRoles.add(userRole.getRole().getRoleName());
int rolePriority = userRole.getRole().getPriority();
if (rolePriority < minPriority || minPriority == -1) {
minPriority = rolePriority;
}
for (RoleAction ra: userRole.getRole().getRoleActions()) {
System.out.println("#########"+ra.getAction().getName());
System.out.println("@@@@@@@@@"+ra.getAction().getId());
map.put(ra.getAction().getName(), ra.getAction().getId());
}
}
<强>解释强>
变量minPriority
初始化为-1
作为占位符值。在循环的每次迭代期间,将当前优先级(rolePriority
)与到目前为止看到的最小值(minPriority
)进行比较,并且可能更新该最小值。此外,在循环的第一次迭代期间,minPriority
被分配给rolePrioirity
。如果您的优先级可以取值-1
,那么您应该将minPriority
初始化为某个从未实际使用过的值。