基于ExtJs6前台,SpringMVC-Spring-Mybatis,resteasy,mysql无限极表设计,实现树状展示数据(treepanel)
2017-08-30 17:48
549 查看
[b]先从后台讲起[/b]
1.表的设计
parent_id就是另外一条记录的id,无限极表设计可以参考http://m.blog.csdn.net/Rookie_Or_Veteran/article/details/75711386
2.mysql查询很容易,关键是要把id,text,parentId查出来
3.dao层
4.service逻辑层
关键逻辑在buildPhoto方法和getChildren方法,这里用了lamda表达式,lamda表达式可以参考我的博客:http://www.cnblogs.com/Java-Starter/p/7424229.html
5.Controller层
没什么操作
[b]前台部分[/b]
1.model层
数据声明,便于查看有哪些数据,少一些数据不设置也可以
2.store层
和后台连接的桥梁
3.View层
4.Controller层
js动作,执行前加载
结果
1.表的设计
parent_id就是另外一条记录的id,无限极表设计可以参考
2.mysql查询很容易,关键是要把id,text,parentId查出来
<?xmlversion="1.0"encoding="UTF-8"?> <!DOCTYPEmapperPUBLIC"-//mybatis.org//DTDMapper3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mappernamespace="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_urlphotoUrl, bp.number, bp.add_timeaddTime, bp.modify_timemodifyTime, bp.parent_idparentId, bp.photo_numberphotoNumber, bp.`description`, bp.`condition`, bp.specification, bp.version_nameversionName FROM bs_photobpINNERJOINbs_brandbbONbp.brand_id=bb.id <includerefid="sqlWhere"/> <includerefid="common.Pagination_Limit"/> </select>
</mapper>
3.dao层
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;
/**
*CreatedbyAdministratoron2017/8/21.
*/
@Repository
publicclassPhotoDao{
@Autowired
@Qualifier("sqlSession")
privateSqlSessionTemplatesqlSession;
publicList<Photo>queryPhoto(PhotoBeanphotoBean){
returnsqlSession.selectList("bs.photo.queryPhoto",photoBean);
}
}
4.service逻辑层
关键逻辑在buildPhoto方法和getChildren方法,这里用了lamda表达式,lamda表达式可以参考我的博客:
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;
/**
*CreatedbyAdministratoron2017/8/21.
*/
@Service
publicclassPhotoService{
@Autowired
privatePhotoDaophotoDao;
privateList<Photo>photoList;
publicList<Photo>queryPhotoArborescence(PhotoBeanphotoBean){
photoList=photoDao.queryPhoto(photoBean);
returnbuildPhoto();
}
/**
*构建资源数
*@returnlist
*/
publicList<Photo>buildPhoto(){
List<Photo>target=newArrayList<>();
if(!photoList.isEmpty()){
//根元素
photoList.stream().filter(photo->photo.getParentId()==0).forEach(photo->{//根元素
List<Photo>children=getChildren(photo);
photo.setChildren(children);
target.add(photo);
});
}
returntarget;
}
privateList<Photo>getChildren(Photophoto){
List<Photo>children=newArrayList<>();
if(!photoList.isEmpty()){
photoList.stream().filter(child->photo.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层
没什么操作
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;
/**
*CreatedbyAdministratoron2017/8/28.
*/
@Controller
@Path("/photo")
publicclassPhotoControllerextendsBaseController{
@Autowired
privatePhotoServicephotoService;
/**
*遍历商品树状结构
*@paramaccessToken
*@paramkeyWord
*@return
*/
@GET
@Path("/queryPhotoArborescence")
@Produces(MediaType.APPLICATION_JSON)
publicPcsResultqueryPhotoArborescence(@QueryParam("keyWord")StringkeyWord){
PhotoBeanphotoBean=newPhotoBean();
photoBean.setKeyWord(keyWord);
List<Photo>list=photoService.queryPhotoArborescence(photoBean);
if(list.size()==0){
returnnewResult(false);
}
returnnewResult(true).setData(list);
}
}
[b]前台部分[/b]
1.model层
数据声明,便于查看有哪些数据,少一些数据不设置也可以
/**
*CreatedbyCon2017/08/05.
*/
Ext.define('Admin.model.photoArborescence.PhotoArborescence',{
extend:'Admin.model.Base',
idProperty:'id',
fields:[
{name:'id',type:'int'},
{name:'name',type:'string'},
{name:'parentId',type:'int'}
]
});
2.store层
和后台连接的桥梁
/**
*CreatedbyCjyon2017/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层
/**
*CreatedbyCjyon2017/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,//自动高度,默认false
animate:true,//展开动画
enableDrag:true,//是否可以拖动(效果上)
enableDD:true,//不进可以拖动,还可以改变节点层次结构
enableDrop:false,//仅仅drop
rootVisible:true,//是否显示根节点,默认true
height:150,
items:[{
title:'自主报价管理',
xtype:'treepanel',
reference:'photoTree',
valueField:'name',
useArrows:true,
autoScroll:true,
height:1150,
store:'photoArborescence.PhotoArborescence'
}]
});
4.Controller层
js动作,执行前加载
/**
*CreatedbyCjyon2017/5/23.
*/
Ext.define('Admin.view.photoArborescence.PhotoArborescenceController',{
extend:'Admin.view.BaseViewController',
alias:'controller.photoArborescence',
/**
*界面渲染的时候加载菜单tree
*/
pictureBeforeRender:function(){
varstore=this.lookupReference('photoTree').getStore();
console.log(store);
store.getRoot().set('expanded',true);
store.load();
}
});
结果
相关文章推荐
- spring-springmvc-mybatis-dubbo-redis-mysql实现soa搭建,数据查询,数据缓存
- J2EE项目使用自定义注解实现基于SpringMVC + Mybatis + Mysql的读写分离
- 基于SpringBoot + Mybatis实现SpringMVC Web项目
- 基于SpringBoot + Mybatis实现SpringMVC Web项目【原创】
- 基于SpringBoot + Mybatis实现SpringMVC Web项目【原创】
- 基于Spring MVC+Hibernate+Spring Security+Mysql 的B/S应用系统平台设计与实现
- 基于现如今流行的SSM(spring springMVC mybatis mysql)框架的hrm人事管理系统后台实例
- 基于SpringBoot + Mybatis实现SpringMVC Web项目【原创】
- 基于SpringBoot + Mybatis实现SpringMVC Web项目
- springboot mybatis mysql实现分表设计
- 利用Spring MVC+Mybatis实现Mysql分页数据查询的过程详解
- 【Spring】SpringMVC之基于注解的实现SpringMVC+MySQL
- Spring Boot 学习二、基于SpringBoot + Mybatis实现SpringMVC Web项目
- 基于SpringBoot + Mybatis实现SpringMVC Web项目
- SpringMVC+Mybatis实现的Mysql分页数据查询的示例
- [Extjs6]treepanel内数据的过滤实现
- [Extjs6]treepanel内数据的过滤实现
- Java Web学习系列——Maven Web项目中集成使用Spring、MyBatis实现对MySQL的数据访问
- 基于SpringBoot + Mybatis实现SpringMVC Web项目【原创】
- 详细步骤!!!idea+springboot+mybatis+jsp+bootstrap实现从mysql查询出数据并显示(源码)