Java + hibernate unlimited Classification

Source: Internet
Author: User

Database Structure:
Create TABLE 'admin _ menu '(
'Menu _ id' int (4) not null auto_increment,
'Menu _ name' varchar (50) default NULL,
'Parent _ id' int (4) default '0 ',
'Menu _ value' varchar (255) default NULL,
'Menu _ sort 'int (4) default '0 ',
'Menu _ description' varchar (50) default NULL,
'Isvalid' tinyint (1) default '0 ',
Primary key ('menu _ id ')
)
Mainly look at the menu_id and parent_id fields.
Persistent Eclipse ing of tables generated by Eclipse: (Note: add the level Attribute by yourself. purpose: to record the depth of the type)
Public class AdminMenu implements java. io. Serializable {
// Fields
Private Integer menuId;
Private String menuName;
Private Integer parentId;
Private String menuValue;
Private Integer menuSort;
Private String menuDescription;
Private Short isvalid;
Private int level;

// Constructors
/** Default constructor */
Public AdminMenu (){
}
/** Minimal constructor */
Public AdminMenu (Integer menuId ){
This. menuId = menuId;
}
/** Full constructor */
Public AdminMenu (Integer menuId, String menuName, Integer parentId, String menuValue, Integer menuSort, String menuDescription, Short isvalid ){
This. menuId = menuId;
This. menuName = menuName;
This. parentId = parentId;
This. menuValue = menuValue;
This. menuSort = menuSort;
This. menuDescription = menuDescription;
This. isvalid = isvalid;
}

// Property accessors
Public Integer getMenuId (){
Return this. menuId;
}
Public void setMenuId (Integer menuId ){
This. menuId = menuId;
}
Public String getMenuName (){
Return this. menuName;
}
Public void setMenuName (String menuName ){
This. menuName = menuName;
}
Public Integer getParentId (){
Return this. parentId;
}
Public void setParentId (Integer parentId ){
This. parentId = parentId;
}
Public String getMenuValue (){
Return this. menuValue;
}
Public void setMenuValue (String menuValue ){
This. menuValue = menuValue;
}
Public Integer getMenuSort (){
Return this. menuSort;
}
Public void setMenuSort (Integer menuSort ){
This. menuSort = menuSort;
}
Public String getMenuDescription (){
Return this. menuDescription;
}
Public void setMenuDescription (String menuDescription ){
This. menuDescription = menuDescription;
}
Public Short getIsvalid (){
Return this. isvalid;
}
Public void setIsvalid (Short isvalid ){
This. isvalid = isvalid;
}
Public int getLevel ()
{
Return level;
}
Public void setLevel (int level)
{
This. level = level;
}
}

/**
* Query the Administrator menu
*
* @ Return
*/
Public static AdminMenu [] selectAdminMenu (String condition)
{
AdminMenu [] adminMenu = null;
String hql = "from AdminMenu as am" + condition;
List list = select (hql );
Object [] o = list. toArray ();
If (o! = Null)
{
AdminMenu = new AdminMenu [o. length];
For (int I = 0; I <o. length; I ++)
{
AdminMenu [I] = (AdminMenu) o [I];
}
}
Return adminMenu;
}

/**
* Tree generation (mainly using Arrays for recursion)
*
* @ Return
*/
Public static ArrayList getTree (AdminMenu [] menu, int parentId, int level, ArrayList list)
{
For (int I = 0; I <menu. length; I ++)
{
If (menu [I]. getParentId (). intValue () = parentId)
{
Menu [I]. setLevel (level );
List. add (menu [I]);
GetTree (menu, menu [I]. getMenuId (), level + 1, list );
}
}
Return list;
}

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.