在專案中使用了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自動生成的臨時表,我怎么去控制這個程序,或者是哪里有問題,麻煩有人能幫忙嗎,拜謝
uj5u.com熱心網友回復:
uj5u.com熱心網友回復:
<resultMap id="BaseResultMap" type="cn.jgsdx.gyx.model.Staff"><id column="id" jdbcType="VARCHAR" property="id" />
<result column="name" jdbcType="VARCHAR" property="name" />
<result column="telephone" jdbcType="VARCHAR" property="telephone" />
<result column="haspda" jdbcType="CHAR" property="haspda" />
<result column="deltag" jdbcType="CHAR" property="deltag" />
<result column="station" jdbcType="VARCHAR" property="station" />
<result column="standard" jdbcType="VARCHAR" property="standard" />
</resultMap>
這是映射的結果集
uj5u.com熱心網友回復:
我也碰到了這個問題,原因是 mybatis-config.xml 里配置的 <property name="dialect" value="https://bbs.csdn.net/topics/oracle"/> 是 oracle,換成 mysql就行了轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/238707.html
標籤:Java EE
下一篇:哪位能提供 一個云主機,同一個專案,供多家不同單位 互不影響使用 ,各看各的資料 各管各的資料的 教學視頻 或 原始碼
