MyBatis implementation reads the tree structure data instance code _java

Source: Internet
Author: User

The MyBatis implementation read tree structure data is described in detail as follows:

Table structure

CREATE TABLE ' Lscrm_function_privilege ' (' id ' int ' unsigned not NULL auto_increment COMMENT ' number ', ' create_id ' varchar (() NOT NULL default ' sys ', ' update_id ' varchar ') is NOT null default ' sys ', ' create_time ' timestamp not NULL default CURR Ent_timestamp COMMENT ' creation time ', ' update_time ' TIMESTAMP not NULL DEFAULT current_timestamp on update current_timestamp NT ' Modify time ', ' validity ' tinyint (3) unsigned not NULL DEFAULT ' 1 ' COMMENT ' validity 1 effective 0. Invalid ', ' code ' varchar (m) NOT null default ' COMMENT ' encoded ', ' function_name ' varchar ' NOT null default ' COMMENT ' name ', ' p arent_id ' tinyint (3) unsigned NOT NULL default ' 0 ' COMMENT ' parent node ', ' Is_leaf_node ' tinyint (3) unsigned NOT null default ' 1 ' COMMENT ' Whether leaf node (the node of leaf nodes is degree 0 is the node with no child node), when adding child nodes, you need to set parent_id is_leaf_node to 0 ', ' sub_system_id ' int (a) unsigned not NULL default ' 0 ' COMMENT ' belongs to Subsystem ', ' Is_hidden ' tinyint (3) unsigned NOT NULL default ' 0 ' COMMENT ' UI is hidden, not displayed on UI ', PRIMARY KE Y (' id ')) engine=innodb auto_increment=22 DEFAULT Charset=utf8Comment= ' child code is created by the parent code \ r \ n such as: Customer.add '; 

constructs the data

INSERT into ' Lscrm_function_privilege ' VALUES (' 1 ', ' sys ', ' sys ', ' 2016-09-07 15:20:40 ', ' 2016-09-07 15:21:17 ', ' 1 ', ' WEB .
PERMISSION ', ' Rights Management ', ' 0 ', ' 0 ', ' 1 ', ' 0 '); INSERT into ' Lscrm_function_privilege ' VALUES (' 2 ', ' sys ', ' sys ', ' 2016-09-07 15:21:12 ', ' 2016-09-07 15:21:40 ', ' 1 ', ' WEB. PERMISSION.
User-mgmt ', ' User Management ', ' 1 ', ' 0 ', ' 1 ', ' 0 '; INSERT into ' Lscrm_function_privilege ' VALUES (' 3 ', ' sys ', ' sys ', ' 2016-09-07 15:22:16 ', ' 2016-09-07 15:22:35 ', ' 1 ', ' WEB. PERMISSION. User-mgmt.
Add ', ' Add user ', ' 2 ', ' 1 ', ' 1 ', ' 0 '; INSERT into ' Lscrm_function_privilege ' VALUES (' 4 ', ' sys ', ' sys ', ' 2016-09-07 15:23:17 ', ' 2016-09-07 15:23:17 ', ' 1 ', ' WEB. PERMISSION. User-mgmt.
MODIFY ', ' Modify user ', ' 2 ', ' 1 ', ' 1 ', ' 0 '; INSERT into ' Lscrm_function_privilege ' VALUES (' 5 ', ' sys ', ' sys ', ' 2016-09-07 16:10:37 ', ' 2016-09-07 16:10:42 ', ' 1 ', ' APP.
Customer ', ' Client Management ', ' 0 ', ' 0 ', ' 2 ', ' 0 '; INSERT into ' Lscrm_function_privilege ' VALUES (' 6 ', ' sys ', ' sys ', ' 2016-09-07 16:11:06 ', ' 2016-09-07 16:11:20 ', ' 1 ', ' APP. CUSTOMER. Add ', ' addingCustomer ', ' 5 ', ' 1 ', ' 2 ', ' 0 '); INSERT into ' Lscrm_function_privilege ' VALUES (' 7 ', ' sys ', ' sys ', ' 2016-09-07 16:11:06 ', ' 2016-09-07 16:11:20 ', ' 1 ', ' APP. CUSTOMER.
MODIFY ', ' Modify Customer ', ' 5 ', ' 1 ', ' 2 ', ' 0 '; INSERT into ' Lscrm_function_privilege ' VALUES (' 8 ', ' sys ', ' sys ', ' 2016-09-07 16:12:33 ', ' 2016-09-07 16:14:10 ', ' 1 ', ' APP. CUSTOMER.
Viewdetail ', ' View customer details ', ' 5 ', ' 1 ', ' 2 ', ' 0 '); INSERT into ' Lscrm_function_privilege ' VALUES (' 9 ', ' sys ', ' sys ', ' 2016-09-07 16:12:33 ', ' 2016-09-07 16:12:33 ', ' 1 ', ' APP. CUSTOMER.
Addvisit ', ' Add a Visit ', ' 5 ', ' 1 ', ' 2 ', ' 0 '); INSERT into ' Lscrm_function_privilege ' VALUES (' ', ' sys ', ' sys ', ' 2016-09-07 16:13:59 ', ' 2016-09-07 16:14:17 ', ' 1 ', ' APP . CUSTOMER.
Viewdemand ', ' View customer purchase demand ', ' 5 ', ' 1 ', ' 2 ', ' 0 '; INSERT into ' Lscrm_function_privilege ' VALUES (' one ', ' sys ', ' sys ', ' 2016-09-07 16:13:59 ', ' 2016-09-07 16:14:17 ', ' 1 ', ' APP . CUSTOMER.
Vieworder ', ' View customer orders ', ' 5 ', ' 1 ', ' 2 ', ' 0 '); INSERT into ' Lscrm_function_privilege ' VALUES (' ', ' sys ', ' sys ', ' 2016-09-07 16:13:59 ', ' 2016-09-07 16:14:17 ', ' 1 ', ' APP. CUSTOMER.
Viewshop ', ' View customer orders ', ' 5 ', ' 1 ', ' 2 ', ' 0 '); INSERT into ' Lscrm_function_privilege ' VALUES (', ' sys ', ' sys ', ' 2016-09-07 16:17:28 ', ' 2016-09-07 16:18:39 ', ' 1 ', ' APP . CUSTOMER.
Viewreply ', ' View grab list ', ' 5 ', ' 1 ', ' 2 ', ' 0 '); INSERT into ' Lscrm_function_privilege ' VALUES (' ', ' sys ', ' sys ', ' 2016-09-07 16:19:32 ', ' 2016-09-07 16:23:51 ', ' 1 ', ' APP . CUSTOMER.
Fastopenshop ', ' Quick open shop ', ' 5 ', ' 1 ', ' 2 ', ' 0 '); INSERT into ' Lscrm_function_privilege ' VALUES (', ' sys ', ' sys ', ' 2016-09-07 16:22:33 ', ' 2016-09-07 16:22:33 ', ' 1 ', ' APP .
DEMAND ', ' demand management ', ' 0 ', ' 0 ', ' 2 ', ' 0 '; INSERT into ' Lscrm_function_privilege ' VALUES (' ', ' sys ', ' sys ', ' 2016-09-07 16:23:21 ', ' 2016-09-07 16:23:21 ', ' 1 ', ' APP . DEMAND.
Private ', ' private ocean demand ', ' 15 ', ' 1 ', ' 2 ', ' 0 '; INSERT into ' Lscrm_function_privilege ' VALUES (' ', ' sys ', ' sys ', ' 2016-09-07 16:23:58 ', ' 2016-09-07 16:23:58 ', ' 1 ', ' APP . DEMAND.
FEEDBACK ', ' Find version feedback ', ' 15 ', ' 1 ', ' 2 ', ' 0 '; INSERT into ' Lscrm_function_privilege ' VALUES (' ', ' sys ', ' sys ', ' 2016-09-0716:24:47 ', ' 2016-09-07 16:24:47 ', ' 1 ', ' APP. DEMAND.
Pushsearch ', ' push sellers search ', ' 15 ', ' 1 ', ' 2 ', ' 0 '); INSERT into ' Lscrm_function_privilege ' VALUES (' ', ' sys ', ' sys ', ' 2016-09-07 16:25:56 ', ' 2016-09-07 16:25:56 ', ' 1 ', ' APP .
KPIs ', ' performance management ', ' 0 ', ' 0 ', ' 2 ', ' 0 '; INSERT into ' Lscrm_function_privilege ' VALUES (' ', ' sys ', ' sys ', ' 2016-09-07 16:27:02 ', ' 2016-09-07 16:27:02 ', ' 1 ', ' APP . Kpi. VIEWDATA ', ' View performance data ', ' 20 ', ' 1 ', ' 2 ', ' 0 ';

Entity Beans

Package com.lianshang.crm.biz.entity;
Import com.google.common.base.MoreObjects;
Import java.util.ArrayList;
Import Java.util.Date;
Import java.util.List; public class Lscrmfunctionprivilegeentity {/** number **/private int id; private string Createid; private string UpdateID;/**
Creation time **/private Date createtime;
/** modification Time **/Private date updatetime=new date (); /** validity 1. Effective 0.
Invalid **/private int validity=1;
/** Code **/private String code;
/** name **/private String functionname;
/** parent Node **/private int parentid;
/** whether the leaf node (leaf nodes are degrees of 0 node is not the node nodes), when adding child nodes, you need to set the parent_id Is_leaf_node to 0**/private int isleafnode;
/** subordinate subsystem **/private int subsystemid;
/**ui is hidden, the UI does not show **/private int ishidden=1;
Private list<lscrmfunctionprivilegeentity> privilegelist = new arraylist<> ();
Get ()/set () omitted ...
} package com.lianshang.crm.biz.entity;
Import java.util.ArrayList;
Import Java.util.Date;
Import java.util.List;
/** * Created by Zhenyu on 2016/9/8.
*/public class Lscrmfunctionprivilegetree {/** number **/private int id;
Private String Createid;
Private String UpdateID;
/** creation time **/private Date createtime;
/** modification Time **/Private date updatetime=new date (); /** validity 1. Effective 0.
Invalid **/private int validity=1;
/** Code **/private String code;
/** name **/private String functionname;
/** parent Node **/private int parentid;
/** whether the leaf node (leaf nodes are degrees of 0 node is not the node nodes), when adding child nodes, you need to set the parent_id Is_leaf_node to 0**/private int isleafnode;
/** subordinate subsystem **/private int subsystemid;
/**ui is hidden, the UI does not show **/private int ishidden=1;
Private list<lscrmfunctionprivilegeentity> privilegelist = new arraylist<> (); }

Mapper Configuration

<?xml version= "1.0" encoding= "UTF-8"?> <! DOCTYPE Mapper Public "-//mybatis.org//dtd mapper 3.0//en" "Http://mybatis.org/dtd/mybatis-3-mapper.dtd" > < Mapper namespace= "Com.lianshang.crm.biz.dao.LscrmFunctionPrivilegeDao" > <cache eviction= "FIFO" Flushinterval = "60000" size= "1024" readonly= "true"/> <resultmap id= "Lscrmfunctionprivilegeresult" Lscrmfunctionprivilegeentity "> <id property=" id "column=" id "/> <result" property= createid "column=" create_id "/> <result property=" UpdateID "column=" update_id "/> <result property=" CreateTime "column=" Create_time "/> <result property=" updatetime "column=" Update_time "/> <result property=" validity "column=" Validity "/> <result property=" code column= "code"/> <result "property=" "functionname" column= Name "/> <result property=" ParentID "column=" parent_id "/> <result property=" Isleafnode "column=" is_leaf_ Node "/> <result property=" subsystemID "column=" Sub_system_id "/> <result property=" Ishidden "column=" Is_hidden "/> </resultMap> <resultmap id=" Subprivilegesresult "type=" lscrmfunctionprivilegeentity "extends=" Lscrmfunctionprivilegeresult "> < Collection property= "Privilegelist" javatype= java.util.ArrayList "column=" id "oftype=" Lscrmfunctionprivilegeentity "select=" selectsubprivileges "></collection> </resultMap> < Resultmap id= "Lscrmfunctionprivilegetreeresult" type= "Lscrmfunctionprivilegetree" extends= "SubPrivilegesResult" > <!--<association property= "Functionprivilege" column= "id" javatype= "lscrmfunctionprivilegeentity" resultmap= "Lscrmfunctionprivilegeresult"/>--> <collection property= "Privilegelist" Java.util.ArrayList "column=" id "oftype=" lscrmfunctionprivilegeentity "select=" Selectsubprivileges "></" collection> </resultMap> <sql id= "Tbl_name" > Lscrm_function_privilege </sql> <sql id= "Role_ Privilege_tbl_name "> Lscrm_role_privilege </sql> <sql id= "select_sql" > select ID, create_id, update_id, Create_time, update_time, validity, code, function_name , parent_id, Is_leaf_node, sub_system_id, Is_hidden from <include refid= "Tbl_name"/> </sql> <select id= " Readallprivileges "resultmap=" Lscrmfunctionprivilegetreeresult "usecache= true" > <include refid= "Select_sql" /> WHERE parent_id = 0 <if test= "subsystemid > 0" > and sub_system_id= #{subsystemid} </if> </select&
Gt <select id= "Selectsubprivileges" resultmap= "Subprivilegesresult" > <include refid= "select_sql"/> WHERE
parent_id = #{id} </select> </mapper> package Com.lianshang.crm.biz.dao;
Import Com.lianshang.crm.api.dto.LscrmFunctionPrivilege;
Import com.lianshang.crm.biz.entity.LscrmFunctionPrivilegeEntity;
Import Com.lianshang.crm.biz.entity.LscrmFunctionPrivilegeTree;
Import Org.apache.ibatis.annotations.Param;
Import java.util.List; Public interface Lscrmfunctionprivilegedao {LIST&LT;LSCRMFUNCTIONPRivilegetree> readallprivileges (@Param ("subsystemID") int subsystemid); }

Service

Package Com.lianshang.crm.biz.service.impl;
Import Com.alibaba.fastjson.JSON;
Import com.google.common.base.Function;
Import Com.lianshang.common.utils.general.GeneralResult;
Import Com.lianshang.common.utils.general.GuavaUtil;
Import Com.lianshang.common.utils.general.StringUtil;
Import Com.lianshang.crm.api.dto.LscrmFunctionPrivilege;
Import Com.lianshang.crm.api.service.LscrmFunctionPrivilegeService;
Import Com.lianshang.crm.biz.dao.LscrmFunctionPrivilegeDao;
Import com.lianshang.crm.biz.entity.LscrmFunctionPrivilegeEntity;
Import Com.lianshang.crm.biz.entity.LscrmFunctionPrivilegeTree;
Import org.springframework.beans.factory.annotation.Autowired;
Import java.util.ArrayList;
Import Java.util.Date;
Import java.util.List;
Import static Com.google.common.collect.FluentIterable.from; public class Lscrmfunctionprivilegeserviceimpl implements Lscrmfunctionprivilegeservice {@Autowired private
Lscrmfunctionprivilegedao Lscrmfunctionprivilegedao; @Override Public GENERALRESULT&LT;STRING&GT readallprivileges (int subsystemid) {list<lscrmfunctionprivilegetree> privilegetrees =
Lscrmfunctionprivilegedao.readallprivileges (subsystemID);
return new Generalresult<> (Json.tojsonstring (privilegetrees)); }
}

Return results

[{' Code ': ' WEB.
PERMISSION "," Createid ":" sys "," createtime ": 1473232840000," functionname ":" Rights Management "," hidden ": 0," id ": 1," Leafnode ": 0, "ParentID": 0, "privilegelist": [{"Code": "WEB. PERMISSION. User-mgmt "," Createid ":" sys "," createtime ": 1473232872000," functionname ":" User Management "," hidden ": 0," id ": 2," Leafnode ": 0," ParentID ": 1," privilegelist ": [{" Code ":" WEB. PERMISSION. User-mgmt. ADD "," Createid ":" sys "," createtime ": 1473232936000," functionname ":" New User "," hidden ": 0," id ": 3," Leafnode ": 1," Parent Id ": 2," privilegelist ": []," subsystemID ": 1," UpdateID ":" sys "," updatetime ": 1473232955000," Validity ": 1}, {" Code ": The WEB. PERMISSION. User-mgmt. MODIFY "," Createid ":" sys "," createtime ": 1473232997000," functionname ":" Modify User "," hidden ": 0," id ": 4," Leafnode ": 1," par Entid ": 2," privilegelist ": []," subsystemID ": 1," UpdateID ":" sys "," updatetime ": 1473232997000," Validity ": 1}]," Subs Ystemid ": 1," UpdateID ":" sys "," updatetime ": 1473232900000," Validity ": 1}]," subsystemID ":1, "UpdateID": "sys", "updatetime": 1473232877000, "Validity": 1}] 

The above is a small set to introduce the MyBatis to read the tree structure data instance code, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!

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.