mybatis物理分页rowbounds临时表别名问题

虫鸟之诗 虫鸟之诗 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
在项目中使用了RowBounds进行分页,但是生成临时表的时候报表的别名错误,可是这不是我生成的sql啊:
Servlet.service() for servlet [dispatcherServlet] in context with path [/bos] threw exception [Request processing failed; nested exception is org.springframework.jdbc.BadSqlGrammarException:
### Error querying database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Every derived table must have its own alias
### The error may exist in file [D:\workspace\spring\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps\bos\WEB-INF\classes\mapper\StaffMapper.xml]
### The error may involve defaultParameterMap
### The error occurred while setting parameters
### SQL: select * from ( select tmp_page.*, rownum row_id from ( select id, name, telephone, haspda, deltag, station, standard from bc_staff ) tmp_page where rownum <= ? ) where row_id > ?
### Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Every derived table must have its own alias
; bad SQL grammar []; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Every derived table must have its own alias] with root cause
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Every derived table must have its own alias
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:408)
at com.mysql.jdbc.Util.getInstance(Util.java:383)
at cn.jgsdx.gyx.dao.BaseDAO.selectPublicListPage(BaseDAO.java:54)
at cn.jgsdx.gyx.service.impl.StaffServiceImpl.selectPublicListPage(StaffServiceImpl.java:25)
at cn.jgsdx.gyx.controller.StaffController.selectPublicListPage(StaffController.java:31)

在我的dao里面分页的代码

public <T> PageList<T> selectPublicListPage(String countSqlID, String sqlID, PageList<T> page, Object obj) {
// 查询总数
Integer total = this.getSqlSession().selectOne(countSqlID, obj);
if (total == null) {
total = 0;
}
//设置查询的条数范围
RowBounds rowBounds = new RowBounds(page.getFirstResult(), page.getPageSize());
// 查询列表信息
List<T> list = this.getSqlSession().selectList(sqlID, obj, rowBounds);
page.setTotal(total != null ? total : 0);
page.setRows(list);
page.setTotalPage((total + page.getPageSize() - 1) / page.getPageSize());
return page;
}

service的实现:

public PageList<Staff> selectPublicListPage(Integer page, Integer rows) {

PageList<Staff> pageList = new PageList<>();
pageList.setCurrentPage(page);
pageList.setPageSize(rows);
Map<String, Object> map = new HashMap<>();
//参数1:查询取派员总数的sqlid,参数二:查询的sqlid
return baseDAO.selectPublicListPage(BosSqlIdDefine.StaffSqlId.QUERY_STAFF_BY_COUNT, BosSqlIdDefine.StaffSqlId.QUERY_STAFF_BY_All, pageList, map);
}

mapper文件:
<select id="queryStaffByCount" resultType="int">
select count(*) as total from
bc_staff
</select>
<select id="queryStaffByAll" resultMap="BaseResultMap">
select <include refid="Base_Column_List" /> from bc_staff
</select>
看了一下报错信息是表的别名的问题,可是这是mybatis自动生成的临时表,我怎么去控制这个过程,或者是哪里有问题,麻烦有人能帮忙吗,拜谢
...全文

相关推荐

评论 3
收藏 已收藏
分享
返回顶部
虫鸟之诗
Java EE 67,535 成员 225,843 内容