Java Object de-weight

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.