removeall overrides equal
list<A> a list If you want to call remove(bo), or removeAll(a), you need to override the equals method of A, because the remove and removeAll methods remove two objects equal to the right from the left,
Then if the equals method is not overridden, the default equals method is used to compare whether the storage locations of the two objects are consistent to determine equality. This obviously does not meet the business needs. We need to rewrite it to make it
Judging based on a few fields such as id (some methods will automatically call equals, and then perform corresponding operations based on the results returned by equals, such as removeAll of list, which needs to be rewritten to meet business needs)
A Bean: in the class
public class OpmUser implements Serializable {
public boolean equals(Object destination)
{
boolean retVal = false;
if ((destination != null) && (destination.getClass().equals(getClass())))
{
OpmUser bean = (OpmUser)destination;
if ((bean.getId() == null) && (getId() == null)) {
retVal = true;
} else if ((bean.getId() != null) && (bean.getId().equals(getId()))) {
retVal = true;
}
}
return retVal;
}
}
@RequestMapping(value="/system/opmRole/userRole")
public String userRole(OpmRole opmRole,HttpServletRequest request,Model modle) {
//OpmUser u= new OpmUser();
//u.setId(opmRole.ge);
//opmUserService.getOpmUser(u);
//modle.addAttribute("vo", opmUserService.getOpmUser(u));
String id = "";//The role Id of the currently assigned user
String organid ="";
String roleId="";
Subject currentUser = SecurityUtils.getSubject();
Session session = currentUser.getSession();
OpmUser user =(OpmUser) session.getAttribute("currentUser");
OpmUserRole u = new OpmUserRole();
u.setUserid(user.getId());
id=opmRole.getId();
List<OpmUserRole> ur=opmUserRoleService.getOpmUserRole(u);//There is one user and one role in this system
if((opmRole.getId()==null||"".equals(opmRole.getId()))&&(ur!=null&&ur.size()>0&&ur.get(0)!=null)){
id = ur.get (0) .getRoleid ();
}
if(ur!=null&&ur.size()>0&&ur.get(0)!=null){
roleId=ur.get(0).getRoleid();//Login user role ID
}
Map<String,Object> param1 = new HashMap<String,Object>();
param1.put("roleId", id);
TbCusMarkVo org = opmRoleService.getOrganByRoleId (param1);
Map<String,Object> param = new HashMap<String,Object>();
param.put("organid", org.getMarketKey()+"");
List <OpmUser> usersAll = ophUserService.getUserByOrgId (param);
Map<String,Object> param2 = new HashMap<String,Object>();
param2.put("rId", id);
List<OpmUser> usersL= opmUserService.getUserByRoleId(param2);
usersAll.removeAll (usersL);
modle.addAttribute("id", opmRole.getId());
modle.addAttribute ("organid", opmRole.getOrganid ());
modle.addAttribute("usersL", usersL);
modle.addAttribute("usersR", usersAll);
if(opmRole.getOrganid()!=null&&!"".equals(opmRole.getOrganid())){
TbCusMark tbCusMark = new TbCusMark();
tbCusMark.setMarketKey(BigDecimal.valueOf(Long.valueOf(opmRole.getOrganid())));
tbCusMark = tbCusMarkService.getMark(tbCusMark);
modle.addAttribute("organName", tbCusMark.getMarketName());
}
if(!"".equals(opmRole.getId())&&opmRole.getId()!=null){
OpmRole ro1 = new OpmRole();
ro1.setId(opmRole.getId());
OpmRole ro = opmRoleService.getOpmRole(ro1);
if(ro!=null){
modle.addAttribute("vo", ro);
}
}
return "/system/opmRole/userRole";
}