jeecg中树形显示的用法

1.GoodsController中显示的方法如下:

@RequestMapping(params = "goodsgrid")
@ResponseBody
public Object goodsgrid(GoodEntity good,HttpServletRequest request, HttpServletResponse response, TreeGrid treegrid) {
CriteriaQuery cq = new CriteriaQuery(GoodEntity.class);
if("yes".equals(request.getParameter("isSearch"))){
treegrid.setId(null);
good.setId(null);
}
if(null != good.getGoodsName()){
org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, good);
}
if (treegrid.getId() != null) {
int c = Integer.parseInt(treegrid.getId());
cq.eq("ggood.id", c);
}
if (treegrid.getId() == null) {
cq.isNull("ggood");
}
cq.add();
List<TreeGrid> goodsList=null;
goodsList =systemService.getListByCriteriaQuery(cq, false);

if(goodsList.size()==0&&good.getGoodsName()!=null){
cq = new CriteriaQuery(GoodEntity.class);
GoodEntity pargood = new GoodEntity();
good.setGgood(pargood);
org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, good);
goodsList =systemService.getListByCriteriaQuery(cq, false);
}
List<TreeGrid> treeGrids = new ArrayList<TreeGrid>();
TreeGridModel treeGridModel = new TreeGridModel();
treeGridModel.setTextField("goodsCode"); 
treeGridModel.setParentText("ggood_goodsName");
treeGridModel.setParentId("ggood_id");
treeGridModel.setSrc("goodsDetail");
treeGridModel.setIdField("id");
treeGridModel.setChildList("goods"); 
Map<String,Object> fieldMap = new HashMap<String, Object>();
fieldMap.put("goodsName", "goodsName");
fieldMap.put("addTime", "addTime");
treeGridModel.setFieldMap(fieldMap);
treeGrids = systemService.treegrid(goodsList, treeGridModel);

JSONArray jsonArray = new JSONArray();
for (TreeGrid treeGrid : treeGrids) {
jsonArray.add(JSON.parse(treeGrid.toJson()));
}
System.out.println(jsonArray);
return jsonArray;
}

父物料下显示子物料的方法

@RequestMapping(params = "setPFunction")
@ResponseBody
public List<ComboTree> setPFunction(HttpServletRequest request, ComboTree comboTree) {
CriteriaQuery cq = new CriteriaQuery(GoodEntity.class);
if(null != request.getParameter("selfId")){
cq.notEq("id", request.getParameter("selfId"));
}
if (comboTree.getId() != null) {
// String fname= jdbcTemplate.queryForObject("select goods_name from t_item where goods_id=?",String.class,comboTree.getId()) ;
cq.eq("ggood.id", comboTree.getId());
}
if (comboTree.getId() == null) {
cq.isNull("ggood");
}
cq.add();
List<GoodEntity> goodsList = systemService.getListByCriteriaQuery(cq, false);
List<ComboTree> comboTrees = new ArrayList<ComboTree>();
ComboTreeModel comboTreeModel = new ComboTreeModel("id", "goodsName", "goods");
comboTrees = systemService.ComboTree(goodsList, comboTreeModel, null, true);
return comboTrees;

}

2.该商品对应的实体类的方法GoodEntity:


@Entity
@Table(name = "wsc_goods", schema = "")
@DynamicUpdate(true)
@DynamicInsert(true)
@SuppressWarnings("serial")
public class GoodEntity implements java.io.Serializable {

/**上级类目*/
private GoodEntity ggood;
/**下级类目*/
private List<GoodEntity> goods = new ArrayList<GoodEntity>();
/**商品代码*/
private java.lang.Integer id;
/**商品名称*/
private java.lang.String goodsName;
/**商品图片*/
private java.lang.String goodsImg;
/**goodsSpe*/
private java.lang.String goodsSpe;
/**商品单价*/
private java.math.BigDecimal goodsPrice;
/**商品详情*/
private java.lang.String goodsDetail;
/**goodsNum*/
private java.lang.Integer goodsNum;
/**添加时间*/
private java.util.Date addTime;

/**ctgId*/
private java.lang.Integer ctgId;
/**isRecommend*/
private java.lang.Integer isRecommend;
/**订单状态*/
private java.lang.Integer status;
/**类型*/
private java.lang.Integer type;
/**物料代码*/
private java.lang.String goodsCode;
/**商品规格*/
private java.lang.String goodsModel;
/**单位*/
private java.lang.String goodsUnit;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "parentid")
public GoodEntity getGgood() {
return ggood;
}

public void setGgood(GoodEntity ggood) {
this.ggood = ggood;
}

@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "ggood")
public List<GoodEntity> getGoods() {
return goods;
}

public void setGoods(List<GoodEntity> goods) {
this.goods = goods;
}
@Column(name ="add_time",nullable=true,length=50)
public java.util.Date getAddTime() {
return addTime;
}

public void setAddTime(java.util.Date addTime) {
this.addTime = addTime;
}
/**
*方法: 取得java.lang.String
*@return: java.lang.String 商品代码
*/

/**
*方法: 取得java.lang.String
*@return: java.lang.String 商品名称
*/
@Column(name ="GOODS_NAME",nullable=true,length=50)
public java.lang.String getGoodsName(){
return this.goodsName;
}
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name ="GOODS_ID",nullable=true,length=255)
public java.lang.Integer getId() {
return id;
}

public void setId(java.lang.Integer id) {
this.id = id;
}

/**
*方法: 设置java.lang.String
*@param: java.lang.String 商品名称
*/
public void setGoodsName(java.lang.String goodsName){
this.goodsName = goodsName;
}
/**
*方法: 取得java.lang.String
*@return: java.lang.String 商品图片
*/
@Column(name ="GOODS_IMG",nullable=true,length=255)
public java.lang.String getGoodsImg(){
return this.goodsImg;
}

/**
*方法: 设置java.lang.String
*@param: java.lang.String 商品图片
*/
public void setGoodsImg(java.lang.String goodsImg){
this.goodsImg = goodsImg;
}
/**
*方法: 取得java.lang.String
*@return: java.lang.String goodsSpe
*/
@Column(name ="GOODS_SPE",nullable=true,length=255)
public java.lang.String getGoodsSpe(){
return this.goodsSpe;
}

/**
*方法: 设置java.lang.String
*@param: java.lang.String goodsSpe
*/
public void setGoodsSpe(java.lang.String goodsSpe){
this.goodsSpe = goodsSpe;
}
/**
*方法: 取得java.lang.String
*@return: java.lang.String 商品单价
*/
@Column(name ="GOODS_PRICE",nullable=true,length=255)
public java.math.BigDecimal getGoodsPrice(){
return this.goodsPrice;
}

/**
*方法: 设置java.lang.String
*@param: java.lang.String 商品单价
*/
public void setGoodsPrice(java.math.BigDecimal goodsPrice){
this.goodsPrice = goodsPrice;
}
/**
*方法: 取得java.lang.String
*@return: java.lang.String goodsNum
*/
@Column(name ="GOODS_NUM",nullable=true,length=255)
public java.lang.Integer getGoodsNum(){
return this.goodsNum;
}

/**
*方法: 设置java.lang.String
*@param: java.lang.String goodsNum
*/
public void setGoodsNum(java.lang.Integer goodsNum){
this.goodsNum = goodsNum;
}

/**
*方法: 取得java.lang.Integer
*@return: java.lang.Integer 订单状态
*/
@Column(name ="STATUS",nullable=true)
public java.lang.Integer getStatus(){
return this.status;
}

/**
*方法: 设置java.lang.Integer
*@param: java.lang.Integer 订单状态
*/
public void setStatus(java.lang.Integer status){
this.status = status;
}

@Column(name ="goods_detail",nullable=true)
public java.lang.String getGoodsDetail() {
return goodsDetail;
}

public void setGoodsDetail(java.lang.String goodsDetail) {
this.goodsDetail = goodsDetail;
}

@Column(name ="ctg_id",nullable=true)
public java.lang.Integer getCtgId() {
return ctgId;
}

public void setCtgId(java.lang.Integer ctgId) {
this.ctgId = ctgId;
}

@Column(name ="is_recommend",nullable=true)
public java.lang.Integer getIsRecommend() {
return isRecommend;
}

public void setIsRecommend(java.lang.Integer isRecommend) {
this.isRecommend = isRecommend;
}

@Column(name ="type",nullable=true)
public java.lang.Integer getType() {
return type;
}

public void setType(java.lang.Integer type) {
this.type = type;
}


@Column(name ="goods_code",nullable=true,length=255)
public java.lang.String getGoodsCode() {
return goodsCode;
}

public void setGoodsCode(java.lang.String goodsCode) {
this.goodsCode = goodsCode;
}
@Column(name ="goods_model",nullable=true,length=255)
public java.lang.String getGoodsModel() {
return goodsModel;
}

public void setGoodsModel(java.lang.String goodsModel) {
this.goodsModel = goodsModel;
}
@Column(name ="goods_unit",nullable=true,length=255)
public java.lang.String getGoodsUnit() {
return goodsUnit;
}

public void setGoodsUnit(java.lang.String goodsUnit) {
this.goodsUnit = goodsUnit;
}

}

要注意的是id和parentid的1对多的关系。

 

3.前端jsp页面的显示页面  goodsList.jsp


<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/context/mytags.jsp"%>
<t:base type="jquery,easyui,tools,DatePicker"></t:base>
<div id="main_depart_list" class="easyui-layout" fit="true">
<div region="center" style="padding: 1px;">
<t:datagrid name="goodsList" title="商品列表"
actionUrl="goodsController.do?goodsgrid"
treegrid="true" idField="id" pagination="false">
<t:dgCol title="common.id" field="id" treefield="id" hidden="true"></t:dgCol>
<t:dgCol title="商品xsxs" field="goodsDetail" treefield="src" width="120"></t:dgCol>
<t:dgCol title="商品单价" field="goodsPrice" treefield="fieldMap.goodsPrice" width="120"></t:dgCol>
<t:dgCol title="商品详情" field="goodsDetail" treefield="fieldMap.goodsDetail" width="120"></t:dgCol>

<t:dgCol title="物料代码" field="goodsCode" treefield="fieldMap.goodsCode" width="120"></t:dgCol>
<t:dgCol title="货号" field="goodsSpe" treefield="fieldMap.goodsSpe" width="120"></t:dgCol>
<t:dgCol title="单位" field="goodsUnit" treefield="fieldMap.goodsUnit" width="120"></t:dgCol>
<t:dgCol title="商品规格" field="goodsModel" treefield="fieldMap.goodsModel" width="120"></t:dgCol>

<%-- <fmt:formatDate pattern="yyyy-MM-dd hh:mm:ss" value="${myDate}" type="both"/> --%>
<%-- <t:dgCol title="添加时间" field="addTime" treefield="fieldMap.addTime" width="120"></t:dgCol> --%>

<t:dgCol title="操作" field="opt" width="100"></t:dgCol>
<t:dgDelOpt url="goodsController.do?del&id={id}" title="删除"></t:dgDelOpt>
</t:datagrid>
<div id="departListtb" style="padding: 3px; height: 25px">
<div style="float: left;">
<a href="#" class="easyui-linkbutton" plain="true" icon="icon-add" onclick="addOrg()">录入</a>
<a href="#" class="easyui-linkbutton" plain="true" icon="icon-edit" onclick="update('编辑','goodsController.do?update','goodsList')">编辑</a>
</div>
</div>
</div>
</div>

<script type="text/javascript">
<!--
$(function() {
var li_east = 0;
});
function addOrg() {
//alert("1122");
var id = "";
var rowsData = $('#goodsList').datagrid('getSelections');
if (rowsData.length == 1) {
id = rowsData[0].id;
}
var url = "goodsController.do?add&id=" + id;
add('录入', url, "goodsList");
}


//-->
</script>

 

 

4.添加商品的jsp页面goods.jsp

<%@ page language="java" import="java.util.*" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/context/mytags.jsp"%>
<!DOCTYPE html>
<html>
<head>
<title>商品信息</title>
<t:base type="jquery,easyui,tools"></t:base>
<script type="text/javascript">
$(function() {
$('#cc').combotree({
url : 'goodsController.do?setPFunction&selfId=${good.id}',
width: 155,
onSelect : function(node) {
// alert(node.text);
// changeOrgType();
}
});
})
/* function changeOrgType() { // 处理组织类型,不显示公司选择项
var orgTypeSelect = $("#orgType");
var optionNum = orgTypeSelect.get(0).options.length;
if(optionNum == 1) {
$("#orgType option:first").remove();
var bumen = '<option value="2" <c:if test="${orgType=='2'}">selected="selected"</c:if>><t:mutiLang langKey="common.goodment"/></option>';
var gangwei = '<option value="3" <c:if test="${orgType=='3'}">selected="selected"</c:if>><t:mutiLang langKey="common.position"/></option>';
orgTypeSelect.append(bumen).append(gangwei);
}
} */
</script>
</head>
<body style="overflow-y: hidden" scroll="no">
<t:formvalid formid="formobj" layout="div" dialog="true" action="goodsController.do?save">
<input id="id" name="id" type="hidden" value="${good.id }">
<fieldset class="step">

<div class="form">
<div class="form">
<label class="Validform_label"> 商品名称: </label>
<input name="goodsName" class="inputxt" value="${good.goodsName }">
<span class="Validform_checktip"></span>
</div>
<div class="form">
<label class="Validform_label"> 上级类目: </label>
<input id="cc" name="ggood.id" value="${good.ggood.id}">
</div>
<div class="form">
<label class="Validform_label"> 商品单价: </label>
<input name="goodsPrice" class="inputxt" value="${good.goodsPrice }">
</div>
<div class="form">
<label class="Validform_label"> 商品详情: </label>
<input name="goodsDetail" class="inputxt" value="${good.goodsDetail }">
</div>

<div class="form">
<label class="Validform_label"> 物料代码: </label>
<input name="goodsCode" class="inputxt" value="${good.goodsCode }">
</div>
<div class="form">
<label class="Validform_label"> 货号: </label>
<input name="goodsSpe" class="inputxt" value="${good.goodsSpe }">
</div>
<div class="form">
<label class="Validform_label"> 单位: </label>
<input name="goodsUnit" class="inputxt" value="${good.goodsUnit }">
</div>
<div class="form">
<label class="Validform_label"> 规格: </label>
<input name="goodsModel" class="inputxt" value="${good.goodsModel }">
</div>
<div class="form">
<label class="Validform_label"> 添加时间: </label>
<c:choose>
<c:when test="${empty good.id}">


<%-- <input name="addTime" class="inputxt" value="${addTime }"> --%>
<input class="Wdate" onClick="WdatePicker()" style="width: 150px" id="addTime" name="addTime" ignore="ignore"
value="<fmt:formatDate value='${addTime}' type="date" pattern="yyyy-MM-dd"/>">
</c:when>
<c:otherwise>
<input class="Wdate" onClick="WdatePicker()" style="width: 150px" id="addTime" name="addTime" ignore="ignore"
value="<fmt:formatDate value='${good.addTime}' type="date" pattern="yyyy-MM-dd"/>">
</c:otherwise>
</c:choose>
</fieldset>
</t:formvalid>
</body>
</html>

 

posted @ 2017-02-07 16:04  许佳挺  阅读(7273)  评论(2编辑  收藏  举报