日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

ext springmvc mysql_基于ExtJs6前台,SpringMVC-Spring-Mybatis,resteasy,mysql无限极表设计,实现树状展示数据(treepanel)...

發布時間:2024/1/23 数据库 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ext springmvc mysql_基于ExtJs6前台,SpringMVC-Spring-Mybatis,resteasy,mysql无限极表设计,实现树状展示数据(treepanel)... 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

先從后臺講起

1.表的設計

2.mysql查詢很容易,關鍵是要把id,text,parentId查出來

/p>

"http://mybatis.org/dtd/mybatis-3-mapper.dtd">

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

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;/*** Created by Administrator on 2017/8/21.*/@Repositorypublic classPhotoDao {

@Autowired

@Qualifier("sqlSession")privateSqlSessionTemplate sqlSession;public ListqueryPhoto(PhotoBean photoBean){return sqlSession.selectList("bs.photo.queryPhoto",photoBean);

}

}

4.service邏輯層

關鍵邏輯在buildPhoto方法和getChildren方法,這里用了lamda表達式,lamda表達式可以參考我的博客: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.*/@Servicepublic classPhotoService {

@AutowiredprivatePhotoDao photoDao;private ListphotoList;public ListqueryPhotoArborescence(PhotoBean photoBean){

photoList=photoDao.queryPhoto(photoBean);returnbuildPhoto();

}/*** 構建資源數

*@returnlist*/

public ListbuildPhoto() {

List target = new ArrayList<>();if (!photoList.isEmpty()) {//根元素

photoList.stream().filter(photo -> photo.getParentId() == 0).forEach(photo -> { //根元素

List children =getChildren(photo);

photo.setChildren(children);

target.add(photo);

});

}returntarget;

}private ListgetChildren(Photo photo) {

List children = new ArrayList<>();if (!photoList.isEmpty()) {

photoList.stream().filter(child-> photo.getId().equals(child.getParentId())).forEach(child ->{

List 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;import javax.ws.rs.*;importjavax.ws.rs.core.MediaType;importjava.util.List;importjava.util.Map;/*** Created by Administrator on 2017/8/28.*/@Controller

@Path("/photo")public class PhotoController extendsBaseController{

@AutowiredprivatePhotoService photoService;/*** 遍歷商品樹狀結構

*@paramaccessToken

*@paramkeyWord

*@return

*/@GET

@Path("/queryPhotoArborescence")

@Produces(MediaType.APPLICATION_JSON)public PcsResult queryPhotoArborescence(@QueryParam("keyWord") String keyWord) {

PhotoBean photoBean= newPhotoBean();

photoBean.setKeyWord(keyWord);

List 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();

}

});

結果

總結

以上是生活随笔為你收集整理的ext springmvc mysql_基于ExtJs6前台,SpringMVC-Spring-Mybatis,resteasy,mysql无限极表设计,实现树状展示数据(treepanel)...的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。