easyUI树形表格

来源:互联网 发布:高中生学java开发 编辑:程序博客网 时间:2024/06/16 00:42

写分类展示,使用的树形表格,三级分类、无分页,用的spring SpringMVC Mybatis 框架,mysql数据库


实体类:

public class Category  implements Serializable{private String cId;private String cName;private String pId;private String clevel;private String categoryImage;private Date createTime;private Date updateTime;private String isShow;//是否显示在首页,1是  2否   一级分类//增加字段private List<Category> children = new ArrayList<Category>(); ;private String state="open";               //get、set方法}

sql语句:

<select id="getCategoryList" parameterType="map" resultType="com.szh.bean.product.Category">SELECT * FROM category WHERE clevel=#{clevel}         <if test="pId != null and pId.length()>0"> AND pId=#{pId} </if></select>

mysql数据库:


controller:

@RequestMapping("/getCategoryList")@ResponseBodypublic Object getCategoryList(HttpServletRequest request){Map<String,Object> map = null;        List<Category> cateList1 = new ArrayList<Category>();        List<Category> cateList2 = new ArrayList<Category>();        List<Category> cateList3 = new ArrayList<Category>();try{map = new HashMap<String,Object>();map.put("clevel", "1");cateList1 = setUpBiz.getCategoryList(map);        for(Category cate1:cateList1){        map.put("clevel", "2");        map.put("pId", cate1.getcId());        cateList2 = setUpBiz.getCategoryList(map);        for(Category cate2:cateList2){        map.put("clevel", "3");        map.put("pId", cate2.getcId());        cateList3 = setUpBiz.getCategoryList(map);        if(cateList3.size()>0){          cate2.setState("closed");          cate2.setChildren(cateList3);                }        }        if(cateList2.size()>0){          cate1.setState("closed");          cate1.setChildren(cateList2);            }}}catch(Exception e){e.printStackTrace();}return JSON.toJSON(cateList1);}

jsp:

<table id="categoryList" class="easyui-treegrid" title="分类列表" data-options="iconCls:'icon-ok',singleSelect:false,fitColumns:true,rownumbers:true,fit:true,url:'setUp/getCategoryList',idField:'cId',treeField:'cName',toolbar:categoryToolbar">      <thead>           <tr>               <th data-options="field:'cb',checkbox:true,align:'center'"></th> <th data-options="field:'cId',width:30,align:'center'">编号</th> <th data-options="field:'cName',width:80,align:'left'">分类名称</th> <th data-options="field:'categoryImage',width:80,align:'center',formatter:SZH.formatImg">分类缩略图</th> <th data-options="field:'createTime',width:80,align:'center'">添加时间</th> <th data-options="field:'updateTime',width:80,align:'center'">修改时间</th> <th data-options="field:'pId'">一级分类pId</th>           </tr>       </thead>   </table>

效果图:



参考资料:点击打开链接

原创粉丝点击