主要分为三类进行记录,
第一类是后台数据查询使用了系统封装的cq,那么只需要对前端代码进行修改就可以;
第二类类是后台使用自己拼写的SQL进行数据查询,那么前后端代码都需要进行修改;
第三类是后台代码使用系统封装的cq,但是前台需要的数据和展示的数据,展示方式不一样的,比如展示中用了数据字典做匹配显示名称,这样在上边的查询框就会默认为下拉框,但是我们想列表展示汉字,查询框用input手动输入,就需要手动改写前台代码
一 后台代码使用cq进行数据查询
(一) 最简单的情况,页面展示的字段和数据库存储字段完全一致,使用系统封装的query属性
<t:dgCol title="性别" field="sex" query="true" queryMode="single" width="120"></t:dgCol>
(二) 使用了字典表的字段,除了query属性,还需要设置dictionary属性,实现将数据库存储的code值转换为name
<t:dgCol title="性别" field="sex" dictionary="sex" query="true" queryMode="single" width="120"></t:dgCol>
三 没有使用字典表,但是存储的是其他表T的A字段,页面需要展示的是T表的B字段,也需要用query和dictionary配合使用
<t:dgCol title="单位" field="depart" dictionary="t_s_depart,id,departname" query="true" queryMode="single" width="120"></t:dgCol>
四 使用的是树形下拉框,需要增加查询条件query,并且手写js,通过后台返回树形数据列表
<t:dgCol title="所属部门" field="depart" query="true" queryMode="single" dictionary="t_s_depart,id,departname"></t:dgCol>
$("#dataListtb [name='depart']").combotree({
url: 'h_Xfaq_ZdfhbwController.do?getComboTreeData'
});
其中#后跟的,是该页面的datagrid标签的name属性+tb,name里加的,是需要进行数据匹配的字段的,field值
二 后台代码手写SQL,增加查询条件
该类情况前台代码的变化和第一种情况一样,后台代码需要接收前台数据,并且加入到查询SQL
前端代码
<t:dgCol title="性别" field="sex" query="true" queryMode="single" width="120"></t:dgCol>
<t:dgCol title="年龄" field="stu_age" query="true" queryMode="single" width="120"></t:dgCol>
后台代码:
@RequestMapping(params = "dataGrid")
public void dataGrid(HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
StringBuffer sql = new StringBuffer("select * from table t");
String sex = request.getParameter("sex");
String age = request.getParameter("stu.age");
if(StringUtil.isNotEmpty(sex)){
sql.append(" and t.sex = '" + sex+ "'");
}
if(StringUtil.isNotEmpty(age)){
sql.append(" and t.stu_age='" + age+ "'");
}
List<Map<String, Object>> resultList= systemService.findForJdbc(sql.toString());
dataGrid.setResults(resultList.subList(
(dataGrid.getPage()-1 )* dataGrid.getRows(),
dataGrid.getPage() * dataGrid.getRows() > resultList.size() ? resultList.size() : dataGrid.getPage() * dataGrid.getRows()));
dataGrid.setTotal(resultList.size());
TagUtil.datagrid(response, dataGrid);
}
注意:jeecg框架在前台,会把字段名中的_转换为.,所以在后台接收数据的时候,也要进行相应的转换,比如示例中的年龄字段
三 前端展示和查询需要的内容不匹配
<div class="easyui-layout" fit="true">
<div region="center" style="padding:0px;border:0px">
<t:datagrid name="showAllStatisticsResults" checkbox="false" pagination="true" fitColumns="false" title="测试页面" actionUrl="testController.do?dotest" idField="id" fit="true" queryMode="group">
<t:dgCol title="主键" field="id" hidden="true" queryMode="single" width="120"></t:dgCol>
<t:dgCol title="所在年份" field="sznf" query="ture" formatter="yyyy" queryMode="group" width="100"></t:dgCol>
</t:datagrid>
<div id="showAllStatisticsResultstb" style="padding:3px;height:30px;background: #F8F8F8">
<div align="left">
<span style="display: -moz-inline-box;display: inline-block;">
<span style="vertical-align:middle;display:-moz-inline-box;display:inline-block;width: 90px;text-align:right;text-overflow:ellipsis;-o-text-overflow:ellipsis; overflow: hidden;white-space:nowrap; " title="所在年份">所在年份:</span>
<select name="sznf" width="100" style="width: 104px">
<option value="" selected="selected">---请选择---</option>
<c:forEach items="${sznfList}" var="dept" >
<option value="${dept.sznf}">${dept.sznf}</option>
</c:forEach>
</select>
</span>
</div>
<div align="right" style="padding:5px">
<a href="#" id="" class="easyui-linkbutton" iconCls="icon-search" onclick="showAllStatisticsResultssearch()">查询 </a>
<a href="#" class="easyui-linkbutton" iconCls="icon-reload" onclick="searchReset('showAllStatisticsResults')">重置</a>
</div>
</div>
<div id="showAllStatisticsResultstb2" style="padding:3px;height:25px;background: #E9E9E9">
</div>
</div>
</div>