Java Object de-weight comparison disgusting say
Requirements: All I have to do is go to the menu with each permission, the menu table structure is ID roleid MenuID get the menu table should be MenuID cannot be duplicated
So write the entity class of the menu table, override the Equals Hashcode method, let the 2 be compared, the following code MENUID as the main comparison field
Package Com.attendance.mvc.model;import Com.jfinal.plugin.activerecord.model;public class Rolemenu extends Model< rolemenu> {//class version, the system automatically generates private static final long Serialversionuid = 1l;//This is what the framework comes with auto-map table fields, which is equivalent to get set comes with
Public final static Rolemenu me = new Rolemenu (); @Overridepublic boolean equals (Object obj) {rolemenu Rolemenu = (rolemenu ) Obj;return this.getstr ("MenuID"). Equals (Rolemenu.getstr ("MenuID"));} @Override public int hashcode () { return this.getstr ("MenuID"). Hashcode ();} }
This allows the entity class to override 2 methods and then use set to automatically
Gets the Permissions menu public list<rolemenu> getrolemenulist () {list<userrole> userrolelist = this. Getuserrolelist (); Irolemenu rolemenubusiness = Businessfactory.createrolemenubusiness (); List<rolemenu> rolemenulist=new arraylist<rolemenu> (); Set<rolemenu> set=new hashset<rolemenu> (); for (Userrole userrole:userrolelist) {List<RoleMenu> Rmlist = Rolemenubusiness.getlistbyroleid (Userrole.getstr ("Roleid")); Set.addall (rmlist);} Rolemenulist.addall (set); return rolemenulist;}
Java Object de-weight