jeecg中列表查詢數據關聯其他表的顯示


1.A表字段:id,name;B表字段:id,name,fid(A表外鍵),現查詢A表和B表的所有數據並且查詢條件A,B都有,在前台頁面list顯示

2.后台方法:

@RequestMapping(params = "datagrid_zh")
public void datagrid_zh(CarRouteEntity ldcHandbookOrder,HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
CriteriaQuery cq = new CriteriaQuery(CarRouteEntity.class, dataGrid);
//查詢條件組裝器
org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, ldcHandbookOrder);
try{
//自定義追加查詢條件
}catch (Exception e) {
throw new BusinessException(e.getMessage());
}
cq.add();
String tiaojian="";
String name=request.getParameter("name");   

if(StringUtils.isNotEmpty(name)) {
tiaojian+=" and a.name>= '"+name+"'";

}  
String sql="select a.id,a.name,b.name as bname from Aa LEFT JOIN B b on a.id=b.fid where 1=1 "+tiaojian;
List<Map<String, Object>> map=jdbcTemplate.queryForList(sql);
dataGrid.setTotal(map.size());
List<Map<String,Object>> maplist=systemService.findForJdbc(sql +" limit "+(dataGrid.getPage()-1)*dataGrid.getRows()+","+dataGrid.getRows(), null);

--oracle用法
//List<Map<String,Object>> maplist=systemService.findForJdbc(sql +" and  ROWNUM>="+(dataGrid.getPage()-1)*dataGrid.getRows()+" and ROWNUM<"+dataGrid.getRows(), null);

dataGrid.setResults(maplist); 
TagUtil.datagrid(response, dataGrid);
}

3.前台頁面

<t:datagrid name="??" checkbox="true" pagination="true" pageSize="10"
sortOrder="desc"
btnCls="bootstrap btn btn-success btn-xs"  
fitColumns="false" title=""
actionUrl="??.do?datagrid_zh"
idField="id" fit="true" queryMode="group">
<t:dgCol title="id" field="id" hidden="true" queryMode="group" width="120"></t:dgCol>
<t:dgCol title="A表名稱" field="name"   query="true" width="120"></t:dgCol>
<t:dgCol title="B表名稱" field="bname"   query="true" width="120"></t:dgCol>
</t:datagrid>

4.技術問題聯系微信xjt199561


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM