基于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();
    }

});

结果

时间: 2024-12-11 15:27:45

基于ExtJs6前台,SpringMVC-Spring-Mybatis,resteasy,mysql无限极表设计,实现树状展示数据(treepanel)的相关文章

课程分享】基于Springmvc+Spring+Mybatis+Bootstrap+jQuery Mobile +MySql教务管理系统

课程讲师:老牛 课程分类:Java框架 适合人群:初级 课时数量:85课时 更新程度:完成 用到技术:Springmvc+Spring+Mybatis+Bootstrap+jQueryMobile 涉及项目:PC端和手机端教务管理系统 需要更多相关资料可以联系 Q2748165793 课程大纲 技能储备 第1课springMVC概述和基础配置 第2课springMVC注解和参数传递 第3课springMVC和JSON数据 第4课springMVC上传下载 第5课springMVC 与 sprin

SpringMVC+Spring+Mybatis+Mysql项目搭建

眼下俺在搭建一个自己的个人站点玩玩.一边练习.一边把用到的技术总结一下,日后好复习. 站点框架大致例如以下图所看到的: 眼下仅仅用到了SpringMVC+Spring+Mybatis+Mysql.把它弄到了自己的server上来玩耍. 后台结构图: 眼下主要分为: view–controller层与前台交互,登陆拦截器 utils–工具类.一些经常使用的工具类. interceptor–拦截器.页面请求地址拦截和预防XSS漏洞拦截. impl–接口类,Service层-进行业务处理. excep

结合项目(Spring+(基于注解的)SpringMVC和Mybatis+uploadify文件上传)--poi解析Excel文件

poi解析Excel文件 1.上传文件至服务器 2.解析Excel文件并返回数据集合 3.将数据保存到服务器 框架======Spring+(基于注解的)SpringMVC和Mybatis===== 第一步: 前台: jsp文件采用的是uploadify <div id="fileQueue"></div> <input type="file" id="brandFile"> js: <script ty

基于Springmvc+Spring+Mybatis+Jqueryeasyui个人信息管理平台(日程管理、天气类型、资产管理、理财规划)

基于Springmvc+Spring+Mybatis+Jqueryeasyui个人信息管理平台(日程管理.天气类型.资产管理.理财规划) 课程讲师老牛 课程分类Java 适合人群中级 课时数量78课时 更新程度完毕 服务类型C类普通服务类课程 用到技术Springmvcspringmybatisjquery easyui 涉及项目个人信息管理好友管理报表实现 咨询QQ2050339477 课程链接http://www.dwz.cn/LO1X3 课程背景 本系统主要用于个人信息的管理通过软件工具对

springmvc学习总结(二) -- maven+springmvc+spring+mybatis+mysql详细搭建整合过程讲解

@[email protected] 写在最前 之前分享过下面这几篇: mybatis学习笔记(五) -- maven+spring+mybatis从零开始搭建整合详细过程(上)(附demo和搭建过程遇到的问题解决方法) mybatis学习笔记(六) -- maven+spring+mybatis从零开始搭建整合详细过程(下) springmvc学习笔记(一) -- 从零搭建,基础入门 这一篇,在这些练习的基础上,将它们整合在一起! 搭建步骤如下 一.新建maven项目,配置环境,测试是否配置成

Ajax+SpringMVC+Spring+Mybatis+MySql+js用户注册实例

林炳文Evankaka原创作品.转载请注明出处http://blog.csdn.net/evankaka 摘要:这几天研究了下Ajax注册的方法,通过在注册时输入用户名或邮箱等,就可以判断这个用户是否存在,以免用户来注册,然后提交了,系统才提示该用户名或邮箱不可用.使用Ajax便可实现这一功能,看了网上的都是php的,想想索性来写一个SpringMVC+Spring+Mybatis的.文章内容用到了很多技术,包括javascript.jquery.json.e表达式等. 先来看看最终效果: 注册

SpringMVC +Spring + MyBatis + Mysql + Redis(作为二级缓存) 配置

转载:http://blog.csdn.net/xiadi934/article/details/50786293 项目环境: 在SpringMVC +Spring + MyBatis + MySQL.Redis部署在Linux虚拟机. 1.整体思路 参考Ehcache实现MyBatis二级缓存代码(Maven引用对应jar查阅) 使用Spring管理Redis连接池 模仿EhcacheCache,实现RedisCache 2.pom.xml中加入Maven依赖 1 <!-- spring-re

Idea SpringMVC+Spring+MyBatis+Maven调整【转】

Idea SpringMVC+Spring+MyBatis+Maven整合 创建项目 File-New Project 选中左侧的Maven,选中右侧上方的Create from archetype,然后选中下方列表中的webapp,然后点击Next 在GroupId和ArtifactId中填入指定内容,点击Next 直接点Next 输入项目名称,Finish Idea会自动开始下载所依赖的包,等待其完成. 项目结构 项目刚建好的时候是没有这些文件的,所以自己手动创建缺少的文件夹(包) 创建完后

SpringMVC+Spring+Mybatis(SSM~Demo) 【转】

SpringMVC+Spring+Mybatis 框架搭建 整个Demo的视图结构: JAR: 下载地址:http://download.csdn.net/detail/li1669852599/8546059 首先,我是使用MyEclipse工具做的这个例子,整合了Sping 3 .Spring MVC 3 .MyBatis框架,演示数据库采用MySQL数据库.例子中主要操作包括对数据的添加(C).查找(R).更新(U).删除(D).我在这里采用的数据库连接池是来自阿里巴巴的Druid,至于D