springboot+mybatis 的org.mybatis.spring.MyBatisSystemException 解決方法


"nested exception is org.apache.ibatis.exceptions.PersistenceException: \r\n### Error querying database.  Cause: java.lang.UnsupportedOperationException\r\n### The error may exist in com/hiteamtech/uws/dao/AppsDao.java (best guess)\r\n### The error may involve com.hiteamtech.uws.dao.AppsDao.findAppInfoByUserId\r\n### The error occurred while handling results\r\n### SQL: SELECT id,app_name,create_time,app_Introduction,user_id from app_info where status = 1 and user_id =? order by id limit ?,?\r\n### Cause: java.lang.UnsupportedOperationException"

以下是我DAO層的代碼

和CONTROLLER層代碼

@Select("SELECT id,app_name,create_time,app_Introduction,user_id from app_info where status = 1 and user_id =#{userId} order by id limit #{page},#{pageCount}")
List findAppInfoByUserId(@Param("userId") int userId, @Param("page") int page1, @Param("pageCount") int pageCount);



@GetMapping(value = "/apps/{userId}/{page}/{pageCount}")
public ResponseEntity<Map> findAppsByUserId(@PathVariable("userId") int userId, @PathVariable("page") int page, @PathVariable("pageCount") int pageCount,Map<String,Object> map){
log.debug("根據用戶ID獲取我的產品:"+ userId + "page:" + page+"pageCount:"+ pageCount);
map.put("appCount",iappService.findAppsCount(userId));
map.put("appInfo",iappService.findAppsByUserId(userId,page,pageCount));
return new ResponseEntity<>(map,HttpStatus.OK);
}


因為controller里返回的JSON數據是Map 所以不能用List 返回DAO

可以對DAO做以下修改

@Select("SELECT id,app_name,create_time,app_Introduction,user_id from app_info where status = 1 and user_id =#{userId} order by id limit #{page},#{pageCount}")
List<Map<String,Object>> findAppInfoByUserId(@Param("userId") int userId, @Param("page") int page1, @Param("pageCount") int pageCount);


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM