实体类有对象属性
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;
}