sql查询,分页问题
本帖最后由 buerguo 于 2018-8-18 22:35 编辑sql语句查询结果集封装好后给前台, 分页只能展示第一页的内容, page只是1, total只是第一页最大条数, 下面是我写的:
dao:====================
/**
* 查询客户信息
*
* @param resultVo
* @param page
* @param rows
* @param request
* @return
*/
@Override
public DataReturn getAllEntities(ResultVo resultVo, int page, int rows, HttpServletRequest request) {
StringBuilder sql = new StringBuilder(
" SELECT " +
" a.acc_no, " +
" a.address, " +
" a.premise_type, " +
" b.BALANCE, " +
" m.meter_id " +
" FROM " +
" A_CUSTOMER_INFO a " +
" LEFT JOIN A_ACCT_BAL b ON a.acc_no = b.ACC_NO " +
" LEFT JOIN A_METER_INFO m ON a.acc_no = m.acc_no " +
" WHERE 1=1 "
);
StringBuilder condition = new StringBuilder("");
ArrayList params = new ArrayList();
String accNo = resultVo.getAccNo();
if (accNo != null && !"".equals(accNo)) {
condition.append(" and a.acc_no like ? ");
params.add("%" + accNo + "%");
}
String sqlQuery = sql.append(condition.toString()).toString();
Query q = getSession().createSQLQuery(sqlQuery);
if (params != null && params.size() > 0) {
for (int i = 0; i < params.size(); i++) {
q.setParameter(i, params.get(i));
}
}
q.setFirstResult((page - 1) * rows).setMaxResults(rows);
List<Object[]> list = q.list();
List<ResultVo> resultVos = new ArrayList<>();
DecimalFormat df = new DecimalFormat("0.00");
if (list != null && list.size() > 0) {
ResultVo resultVo1 = null;
for (int i = 0; i < list.size(); i++) {
resultVo1 = new ResultVo();
Object[] objects = list.get(i);
if (objects != null) {
resultVo1.setAccNo(objects[0] != null ? (String) objects[0] : "");
resultVo1.setAddress(objects[1] != null ? (String) objects[1] : "");
resultVo1.setPremiseType(objects[2] != null ? (String) objects[2] : "");
if (objects[3] != null) {
BigDecimal big3 = ((BigDecimal) objects[3]).setScale(2, BigDecimal.ROUND_HALF_UP);
double db3 = big3.doubleValue();
String format = df.format(db3);
BigDecimal bigbal = new BigDecimal(format);
resultVo1.setBalance(bigbal);
}
resultVo1.setMeterId(objects[4] != null ? (String) objects[4] : "");
resultVos.add(resultVo1);
}
}
}
int count = list.size();
DataReturn data = new DataReturn();
data.setRows(resultVos);
data.setTotal(count);
return data;
}
controller:====================
@RequestMapping(params = "definedDatagrid")
public void definedDatagrid(ResultVo resultVo, HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
DataReturn dataReturn = this.topupRecordService.getAllEntities(resultVo,dataGrid.getPage(),dataGrid.getRows(),request);
dataGrid.setResults(dataReturn.getRows());
dataGrid.setTotal((int)dataReturn.getTotal());
TagUtil.datagrid(response, dataGrid);
}
jsp:====================
<div class="easyui-layout" fit="true">
<div region="center" style="padding:0px;border:0px">
<t:datagrid name="collectionAgentInfoList" checkbox="false" pageSize="10" sortName="accNo" pagination="true" fitColumns="true" title="Collection Agent Information List"
superQuery="false" actionUrl="topupRecordController.do?definedDatagrid" idField="accNo" fit="true" queryMode="group" filter="true" >
<t:dgCol align="center" title="Account No." query="true" field="accNo" width="100"></t:dgCol>
<t:dgCol align="center" title="Credit Balance" field="balance" width="80"></t:dgCol>
<t:dgCol align="center" title="Premise Type" field="premiseType" width="80"></t:dgCol>
<t:dgCol align="center" title="Meter No." field="meterId" width="120"></t:dgCol>
<t:dgCol align="center" title="Customer Address" field="address" width="200"></t:dgCol>
</t:datagrid>
</div>
</div>
我写的哪里有问题吗?怎么修改呢
自己写的代码,我们这边没办法检查,你可以参考jeecg的例子 admin 发表于 2018-8-20 11:25 static/image/common/back.gif
自己写的代码,我们这边没办法检查,你可以参考jeecg的例子
解决了, 谢谢
页:
[1]