处理级联问题

实体类有对象属性

public class ProductSmallType {

	private Integer id;//编号
	
	private String name;//名称
	
	private String remarks;//备注
	
	private ProductBigType bigType;
	
	private List<Product> productList = new ArrayList<Product>();

前台需要获取对象属性里的内容,而避免不发生内循环

<table id="dg" title="商品小类管理" class="easyui-datagrid"
	 fitColumns="true" pagination="true" rownumbers="true"
	 url="${pageContext.request.contextPath }/admin/smallType/list.do" fit="true" toolbar="#tb">
	 <thead>
	 	<tr>
	 		<th field="cb" checkbox="true" align="center"></th>
	 		<th field="id" width="50" align="center">编号</th>
	 		<th field="name" width="100" align="center">商品小类名称</th>
	 		<th field="bigType.id" width="100" align="center" formatter="formatBigTypeId" hidden="true">所属商品大类id</th>
	 		<th field="bigType.name" width="100" align="center" formatter="formatBigTypeName">所属商品大类</th>
	 		<th field="remarks" width="200" align="center">备注</th>
	 	</tr>
	 </thead>
	</table>

后台需要加上这几句话

JsonConfig jsonConfig = new JsonConfig();
jsonConfig.setExcludes(new String[] {"productList"});
jsonConfig.registerJsonValueProcessor(ProductBigType.class,new ObjectJsonValueProcessor(new String[]{"id","name"}, ProductBigType.class));
@RequestMapping("/list")
	public String list(ProductSmallType productSmallType,@RequestParam(value="page",required=false)String page,@RequestParam(value="rows",required=false)String rows,HttpServletRequest request,HttpServletResponse response) throws Exception{
		PageBean pageBean = new PageBean(Integer.parseInt(page),Integer.parseInt(rows));
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("name", StringUtil.formatLike(productSmallType.getName()));
		map.put("start", pageBean.getStart());
		map.put("size", pageBean.getPageSize());
		List<ProductSmallType> productSmallTypeList = productSmallTypeService.productSmallTypeList(map);
		Long total = productSmallTypeService.getTotal(map);
		JSONObject result = new JSONObject();
		JsonConfig jsonConfig = new JsonConfig();
		jsonConfig.setExcludes(new String[] {"productList"});
		jsonConfig.registerJsonValueProcessor(ProductBigType.class,new ObjectJsonValueProcessor(new String[]{"id","name"}, ProductBigType.class));
		JSONArray jsonArray = JSONArray.fromObject(productSmallTypeList,jsonConfig);
		result.put("rows", jsonArray);
		result.put("total", total);
		ResponseUtil.write(response, result);
		return null;
	}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值