基于ExtJs6前台,SpringMVC-Spring-Mybatis,resteasy,mysql无限极表设计,实现树状展示数据(treepanel)
先从后台讲起
1.表的设计
parent_id就是另外一条记录的id,无限极表设计可以参考 http://m.blog.csdn.net/Rookie_Or_Veteran/article/details/75711386

2.mysql查询很容易,关键是要把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">
<select id="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 photoUrl,
bp.number,
bp.add_time addTime,
bp.modify_time modifyTime,
bp.parent_id 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 <include refid="sqlWhere"/>
<include refid="common.Pagination_Limit"/>
</select>
</mapper>
3.dao层
package com.xgt.dao.bs; import com.xgt.bean.bs.PhotoBean;
import com.xgt.dao.entity.bs.Photo;
import org.jboss.resteasy.annotations.Query;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository; import java.util.List; /**
* Created by Administrator on 2017/8/21.
*/
@Repository
public class PhotoDao {
@Autowired
@Qualifier("sqlSession")
private SqlSessionTemplate sqlSession; public List<Photo> queryPhoto(PhotoBean photoBean){
return sqlSession.selectList("bs.photo.queryPhoto",photoBean);
}
}
4.service逻辑层
关键逻辑在buildPhoto方法和getChildren方法,这里用了lamda表达式,lamda表达式可以参考我的博客:http://www.cnblogs.com/Java-Starter/p/7424229.html
package com.xgt.service.bs; import com.xgt.bean.bs.PhotoBean;
import com.xgt.dao.bs.PhotoDao;
import com.xgt.dao.entity.bs.Brand;
import com.xgt.dao.entity.bs.Photo;
import org.apache.commons.collections.map.HashedMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import java.util.ArrayList;
import java.util.List;
import java.util.Map; /**
* Created by Administrator on 2017/8/21.
*/
@Service
public class PhotoService {
@Autowired
private PhotoDao photoDao; private List<Photo> photoList;
public List<Photo> queryPhotoArborescence(PhotoBean photoBean){
photoList = photoDao.queryPhoto(photoBean);
return buildPhoto();
}
/**
* 构建资源数
* @return list
*/
public List<Photo> buildPhoto() {
List<Photo> target = new ArrayList<>();
if (!photoList.isEmpty()) {
// 根元素
photoList.stream().filter(photo -> photo.getParentId() == 0).forEach(photo -> { // 根元素
List<Photo> children = getChildren(photo);
photo.setChildren(children);
target.add(photo);
});
}
return target;
} private List<Photo> getChildren(Photo photo) {
List<Photo> children = new ArrayList<>();
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);
});
}
return children;
}
}
5.Controller层
没什么操作
package com.xgt.controller; import com.xgt.bean.bs.BrandBean;
import com.xgt.bean.bs.PhotoBean;
import com.xgt.common.BaseController;
import com.xgt.common.PcsResult;
import com.xgt.dao.entity.bs.Photo;
import com.xgt.exception.EnumPcsServiceError;
import com.xgt.service.bs.PhotoService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.jboss.resteasy.annotations.Form;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import java.util.List;
import java.util.Map; /**
* Created by Administrator on 2017/8/28.
*/
@Controller
@Path("/photo")
public class PhotoController extends BaseController{
@Autowired
private PhotoService photoService; /**
* 遍历商品树状结构
* @param accessToken
* @param keyWord
* @return
*/
@GET
@Path("/queryPhotoArborescence")
@Produces(MediaType.APPLICATION_JSON)
public PcsResult queryPhotoArborescence(@QueryParam("keyWord") String keyWord) {
PhotoBean photoBean = new PhotoBean();
photoBean.setKeyWord(keyWord);
List<Photo> list = photoService.queryPhotoArborescence(photoBean);
if(list.size()==0){
return newResult(false);
}
return newResult(true).setData(list);
} }
前台部分
1.model层
数据声明,便于查看有哪些数据,少一些数据不设置也可以
/**
* Created by C on 2017/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层
和后台连接的桥梁
/**
* 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层
/**
* 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,// 自动高度,默认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动作,执行前加载
/**
* Created by Cjy on 2017/5/23.
*/
Ext.define('Admin.view.photoArborescence.PhotoArborescenceController', {
extend: 'Admin.view.BaseViewController',
alias: 'controller.photoArborescence', /**
* 界面 渲染的时候加载 菜单 tree
*/
pictureBeforeRender: function () {
var store = this.lookupReference('photoTree').getStore();
console.log(store);
store.getRoot().set('expanded', true);
store.load();
} });
结果

基于ExtJs6前台,SpringMVC-Spring-Mybatis,resteasy,mysql无限极表设计,实现树状展示数据(treepanel)的更多相关文章
- SSM(SpringMVC+Spring+MyBatis)三大框架使用Maven快速搭建整合(实现数据库数据到页面进行展示)
本文介绍使用SpringMVC+Spring+MyBatis三大框架使用Maven快速搭建一个demo,实现数据从数据库中查询返回到页面进行展示的过程. 技术选型:SpringMVC+Spring+M ...
- 3.springMVC+spring+Mybatis整合Demo(单表的增删该查,这里主要是贴代码,不多解释了)
前面给大家讲了整合的思路和整合的过程,在这里就不在提了,直接把springMVC+spring+Mybatis整合的实例代码(单表的增删改查)贴给大家: 首先是目录结构: 仔细看看这个目录结构:我不详 ...
- SpringMVC+Spring+Mybatis+Maven+mysql整合
一.准备工作1.工具:jdk1.7.0_80(64)+tomcat7.0.68+myeclipse10.6+mysql-5.5.48-win322. 开发环境安装配置.Maven项目创建(参考:htt ...
- springmvc spring mybatis插入mysql中文乱码
springmvc 插入mysql数据库中文乱码问题: 1.将页面中的编码改成utf-8 2.用SQLyog右击->改变数据库 以上两步可以保证页面数据编码一致 3.在mybatis连接的地方加 ...
- SpringMVC+Spring+mybatis项目从零开始--分布式项目结构搭建
转载出处: SpringMVC+Spring+mybatis+Redis项目从零开始--分布式项目结构搭建 /** 本文为博主原创文章,如转载请附链接. **/ SSM框架web项目从零开始--分布式 ...
- 基于SpringMVC+Spring+MyBatis实现秒杀系统【概况】
前言 本教程使用SpringMVC+Spring+MyBatis+MySQL实现一个秒杀系统.教程素材来自慕课网视频教程[https://www.imooc.com/learn/631].有感兴趣的可 ...
- SpringMVC+Spring+Mybatis+Mysql项目搭建
眼下俺在搭建一个自己的个人站点玩玩.一边练习.一边把用到的技术总结一下,日后好复习. 站点框架大致例如以下图所看到的: 眼下仅仅用到了SpringMVC+Spring+Mybatis+Mysql.把它 ...
- springmvc学习总结(二) -- maven+springmvc+spring+mybatis+mysql详细搭建整合过程讲解
@_@ 写在最前 之前分享过下面这几篇: mybatis学习笔记(五) -- maven+spring+mybatis从零开始搭建整合详细过程(上)(附demo和搭建过程遇到的问题解决方法) myba ...
- maven+springmvc+spring+mybatis+mysql详细搭建整合过程讲解
转自:https://www.cnblogs.com/lmei/p/7190755.html?utm_source=itdadao&utm_medium=referral @_@ 写在最前 之 ...
随机推荐
- HashTable的故事----Jdk源码解读
HashTable的故事 很早之前,在讲HashMap的时候,我们就说过hash是散列,把...弄碎的意思.hashtable中的hash也是这个意思,而table呢,是指数据表格,也就是说hasht ...
- jenkins - ssh Server Groups Center
- jmeter 接口重放(投票活动)
目的 这几天公司弄了个投票的活动,召集大家一起投票.自己比较懒,就想这个投票是不是可以直接抓包进行重放通过jmeter集成到jenkins里面去每天来跑.试了下成功了,这里把对应的方案抛出来. 第一步 ...
- LeetCode-Maximum Subarray[dp]
Maximum Subarray Find the contiguous subarray within an array (containing at least one number) which ...
- 【逻辑漏洞】基于BurpSuite的越权测试实战教程
一.什么是越权漏洞?它是如何产生的? 越权漏洞是Web应用程序中一种常见的安全漏洞.它的威胁在于一个账户即可控制全站用户数据.当然这些数据仅限于存在漏洞功能对应的数据.越权漏洞的成因主要是因为开发人员 ...
- opencc 繁体简体互转 (C++示例)
繁体字通常采用BIG5编码,简体字通常采用GBK或者GB18030编码,这种情况下,直接使用iconv(linux下有对应的命令,也有对应的C API供编程调用)就行.对于默认采用utf-8 ...
- Swift 细节
1.swift ?和 !的区别 1.1 Swift语言使用var定义变量,但和别的语言不同,Swift里不会自动给变量赋初始值,也就是说变量不会有默认值,所以要求使用变量之前必须要对其初始化.如果在使 ...
- zabbix_server----邮箱报警
zabbix邮件报警部署!!!!!!!!!!!!!!! Zabbix监控服务端.客户端都已经部署完成,被监控主机已经添加,Zabiix监控运行正常,通过查看Zabbix监控服务器,可以了解服务器的运行 ...
- ABP+AdminLTE+Bootstrap Table权限管理系统第一节--使用ASP.NET Boilerplate模板创建解决方案
"abp是ASP.NET Boilerplate简称,是一个用最佳实践和流行技术开发现代WEB应用程序的新起点,它旨在成为一个通用的WEB应用程序框架和项目模板" abp官方网站: ...
- java配置mongo最大连接数
最近做压测,其中有个交易涉及到对mongo的操作. 单机压到1500UV的时候出现如下错误: 一看,原来是mongo配置的最大连接数不够: 我们来看看mongo的官方文档: connectionPer ...