错误如下:SqlMapClient operation; bad SQL grammar []; nested exception is com.ibatis.common.jdbc.exception.NestedSQLException: --- The error occurred in hsat/persistent/model/Norm.xml. --- The error occurred while applying a result map. --- Check the Norm.queryNorm-AutoResultMap. --- Check the result mapping for the 'PAGESORTID' property. --- Cause: java.sql.SQLException: 列名无效
错误发生代码如下:发生错误原因方法如下:
[code=Java]
public String doQueryNorm() {
try {
//获取页面要显示的行数和页数
int currentPageInt = 1;
String strCurrentPage = currentPage;
if (strCurrentPage != null && !"".equals(strCurrentPage)) {
try {
currentPageInt = Integer.parseInt(strCurrentPage);
} catch (NumberFormatException e) {
e.printStackTrace();
this.addActionError(e.getMessage());
}
}
int offset = (currentPageInt - 1) * pages;
int limit = pages;
//获取页面传递的查询条件
HashMap hashmap = new HashMap();
if (!"".equals(normId_q) && normId_q != null) {
hashmap.put("normId", "%" + normId_q + "%");
}
if (!"".equals(normName_q) && normName_q != null) {
hashmap.put("normName_q", "%" + normName_q + "%");
}
if (!"".equals(reportDep) && reportDep != null) {
hashmap.put("depid", "%" + reportDep + "%");
}
//查询数据库
int record = normService.queryCountNorm(hashmap);
List lst = normService.queryNorm(hashmap, offset,limit);
                             /*这行没有问题,将offset,limit改成0、-1也没有问题,但是我的需求是导出excel的时候要将符合条件的都导出来,也就是说offset和limit必须是0或-1,于是我新添excellist
                              List excellist = normService.queryNorm(hashmap, 0,-1);
然后在下面List mapList = this.convertListToMap(excellist );转化excellist 这个list。但是新添这句话的时候错误就出来了。无法理解。如果我不加这句话,程序没错,也可以导出excel。*/
System.out.println("\n\n list 的长度是:" + lst.size() + "\n\n");
Pageable pg = null;
try {
pg = new IbatisPage(lst, record, currentPageInt, pages);
} catch (PageException e) {
pg = null;
}
ServletActionContext.getRequest().setAttribute("pages", pg);
NormList = pg.getResult();

// 导出Excel
if ("true".equals(toexcel)) {
List mapList = this.convertListToMap(lst);
for (int i = 0; i < mapList.size(); i++) {
HashMap hashMap = (HashMap) mapList.get(i); if (hashMap.get("STATUS").toString().equals("01")) {
hashMap.put("STATUS", "正常");
} else if (hashMap.get("STATUS").toString().equals("02")) {
hashMap.put("STATUS", "修订");
} else if (hashMap.get("STATUS").toString().equals("03")) {
hashMap.put("STATUS", "报废");
}
}
this.toExcel(ServletActionContext.getResponse(), mapList,field, title, subTitle);
}
} catch (Exception e) {
e.printStackTrace();
this.addActionError(e.getMessage());
}
return SUCCESS;
}[/code]

解决方案 »

  1.   

     List lst = normService.queryNorm(hashmap, offset,limit); List mapList = this.convertListToMap(lst); 我觉得你这两个地方有问题 ,直接用前一个对象就可以了,没必要再写一遍。。
      

  2.   

     Check the result mapping for the 'PAGESORTID' property. --- Cause: java.sql.SQLException: 列名无效
    看看你的程序里的 PAGESORTID 和你的实体类中的属性,数据库中的字段是不是对应吧
      

  3.   

    跟数据库没有关系啊。
    我只是写了这行 List excellist = normService.queryNorm(hashmap, 0,-1);
    才报错的。
    因为一开始初始化我要查10条数据显示,然后当我点击导出excel时我要把符合条件的全部查找出来,所以才有这一行的。
    但是写了这行就报错。。