Tree display data (Treepanel) based on ExtJs6 foreground, Springmvc-spring-mybatis,resteasy,mysql infinite pole table design

Source: Internet
Author: User
Tags mysql query jboss

Let's start with the backstage.

1. Design of the table

PARENT_ID is the ID of another record, and the infinite pole table design can refer to http://m.blog.csdn.net/Rookie_Or_Veteran/article/details/75711386

2.mysql query is easy, the key is to find out Id,text,parentid

<? 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= "Bs.photo">
<SelectID= "Queryphoto"ParameterType= "Com.xgt.bean.bs.PhotoBean"Resulttype= "Com.xgt.dao.entity.bs.Photo">SELECT bp.id, bb. ' Name ' brandname, BP. ' Name ' text, Bp.photo_url ph Otourl, Bp.number, Bp.add_time addtime, Bp.modify_time modifytime, bp.parent_i D ParentID, Bp.photo_number Photonumber, BP. ' Description ', BP. ' Condition ', BP. Specification, Bp.version_name versionname from Bs_photo bp INNER JOIN bs_brand BB on bp.brand_id = Bb.id<includerefID= "Sqlwhere"/> <includerefID= "Common." Pagination_limit "/> </Select>
</mapper>

3.dao Layer

 Packagecom.xgt.dao.bs;ImportCom.xgt.bean.bs.PhotoBean;ImportCom.xgt.dao.entity.bs.Photo;ImportOrg.jboss.resteasy.annotations.Query;Importorg.mybatis.spring.SqlSessionTemplate;Importorg.springframework.beans.factory.annotation.Autowired;ImportOrg.springframework.beans.factory.annotation.Qualifier;Importorg.springframework.stereotype.Repository;Importjava.util.List;/*** Created by Administrator on 2017/8/21.*/@Repository Public classPhotodao {@Autowired @Qualifier ("Sqlsession")    Privatesqlsessiontemplate sqlsession;  PublicList<photo>Queryphoto (Photobean photobean) {returnSqlsession.selectlist ("Bs.photo.queryPhoto", Photobean); }
}

4.service Logic Layer

The key logic is in the Buildphoto method and the GetChildren method, where the LAMDA expression is used, and the LAMDA expression can refer to my blog: http://www.cnblogs.com/Java-Starter/p/7424229.html

 Packagecom.xgt.service.bs;ImportCom.xgt.bean.bs.PhotoBean;ImportCom.xgt.dao.bs.PhotoDao;ImportCom.xgt.dao.entity.bs.Brand;ImportCom.xgt.dao.entity.bs.Photo;ImportOrg.apache.commons.collections.map.HashedMap;Importorg.springframework.beans.factory.annotation.Autowired;ImportOrg.springframework.stereotype.Service;Importjava.util.ArrayList;Importjava.util.List;ImportJava.util.Map;/*** Created by Administrator on 2017/8/21.*/@Service Public classPhotoservice {@AutowiredPrivatePhotodao Photodao; PrivateList<photo>photolist;  PublicList<photo>queryphotoarborescence (Photobean photobean) {photolist=Photodao.queryphoto (Photobean); returnBuildphoto (); }/*** Number of build resources *@returnList*/     PublicList<photo>Buildphoto () {List<Photo> target =NewArraylist<>(); if(!Photolist.isempty ()) {            //root elementPhotolist.stream (). Filter (photo, photo.getparentid () = = 0). ForEach (Photo, {//root elementlist<photo> children =GetChildren (photo);                Photo.setchildren (children);            Target.add (photo);        }); }        returnTarget; }    PrivateList<photo>GetChildren (Photo photo) {List<Photo> children =NewArraylist<>(); if(!Photolist.isempty ()) {Photolist.stream (). Filter ( childPhoto.getid (). Equals (Child.getparentid ())). ForEach (Child-{List<Photo> tmp =GetChildren (child);                Child.setchildren (TMP); if(Tmp.isempty ()) {Child.setleaf (true);            } children.add (child);        }); }        returnchildren; }}

5.Controller Layer

Nothing to do.

 PackageCom.xgt.controller;ImportCom.xgt.bean.bs.BrandBean;ImportCom.xgt.bean.bs.PhotoBean;ImportCom.xgt.common.BaseController;ImportCom.xgt.common.PcsResult;ImportCom.xgt.dao.entity.bs.Photo;ImportCom.xgt.exception.EnumPcsServiceError;ImportCom.xgt.service.bs.PhotoService;Importorg.apache.shiro.authz.annotation.RequiresPermissions;ImportOrg.jboss.resteasy.annotations.Form;Importorg.springframework.beans.factory.annotation.Autowired;ImportOrg.springframework.stereotype.Controller;Importjavax.ws.rs.*;ImportJavax.ws.rs.core.MediaType;Importjava.util.List;ImportJava.util.Map;/*** Created by Administrator on 2017/8/28.*/@Controller @path ("/photo") Public classPhotocontrollerextendsbasecontroller{@AutowiredPrivatePhotoservice Photoservice;    /*** Traverse the commodity tree structure *@paramAccesstoken *@paramKeyWord *@return     */@GET @Path ("/queryphotoarborescence") @Produces (Mediatype.application_json) PublicPcsresult queryphotoarborescence (@QueryParam ("KeyWord") String KeyWord) {Photobean Photobean=NewPhotobean ();        Photobean.setkeyword (KeyWord); List<Photo> list =photoservice.queryphotoarborescence (Photobean); if(List.size () ==0){            returnNewresult (false); }        returnNewresult (true). SetData (list); }}

Front desk Section

1.model Layer

Data declaration, easy to see what data, less data is not set or

/**/ext.define (' Admin.model.photoArborescence.PhotoArborescence ', {    ' Admin.model.Base '    , ' id ', fields    : [        ' id ', type: ' int '},        ' Name ', type: ' String '},        ' ParentID ', type: ' int '}    ]});

2.store Layer

Bridges connected to the background

/** * Created by Cjy on 2017/08/05.*/Ext.define (' Admin.store.photoArborescence.PhotoArborescence ', {extend:' Ext.data.TreeStore ', requires: [' Common.config '], StoreId:' Photoarborescence.photoarborescence ', Root: {ID:0, Text:‘‘}, Proxy: {type:' Ajax ', API: {Read:Common.Config.requestPath (' Photo ', ' queryphotoarborescence ')}, Reader: {type:' JSON ', Rootproperty:' Data '        }    }});

3.View Layer

/** * Created by Cjy on 2017/5/23.*/Ext.define (' Admin.view.photoArborescence.PhotoArborescence ', {extend:' Ext.container.Container ', Xtype:' Photoarborescence ', requires: [' Ext.tree.Panel ',        ' Admin.view.photoArborescence.PhotoArborescenceController '], controller:' Photoarborescence ', layout:' Fit ', listeners: {beforerender:' Picturebeforerender '}, defaults: {height:' 100% '}, Autoheight:true,//Auto Height, default falseAnimate:true,//Expand AnimationsEnabledrag:true,//Whether you can drag (effect)Enabledd:true,//You can drag, you can also change the node hierarchyEnabledrop:false,//Just dropRootvisible:true,//whether the root node is displayed, by default trueheight:150, items: [{title:' Self-quote management ', Xtype:' Treepanel ', reference:' Phototree ', Valuefield:' Name ', Usearrows:true, AutoScroll:true, Height:1150, Store:' Photoarborescence.photoarborescence '    }]});

4.Controller Layer

JS action, load before execution

/** * Created by Cjy on 2017/5/23.*/Ext.define (' Admin.view.photoArborescence.PhotoArborescenceController ', {extend:' Admin.view.BaseViewController ', alias:' Controller.photoarborescence ',    /** * Interface rendering when loading menu tree*/Picturebeforerender:function () {        varstore = This. Lookupreference (' Phototree '). GetStore ();        Console.log (store); Store.getroot (). Set (' Expanded ',true);    Store.load (); }});

Results

Tree display data (Treepanel) based on ExtJs6 foreground, Springmvc-spring-mybatis,resteasy,mysql infinite pole table design

Related Article

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.