报错内容
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException:
### Error querying database. Cause: java.lang.UnsupportedOperationException
### The error may exist in file [E:\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\day13_Pritice\WEB-INF\classes\com\wu\employee\mapper\IDepartmentMapper.xml]
### The error may involve com.wu.employee.mapper.IDepartmentMapper.getAllDepartment
### The error occurred while handling results
### SQL: SELECT * FROM department
### Cause: java.lang.UnsupportedOperationException
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:943)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:822)
javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:807)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
错误截图
原因分析
- SQL 语句写错了。此处SQl没问题。
- mapper配置文件中的结果集写错了,假如返回的结果集是多个JavaBean,那么resultType=”javaBean”, 例如:查询Department的List列表,resultType应该写成Department的全类名而不是java.util.List
错误示范:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.wu.employee.mapper.IDepartmentMapper">
<!-- 查看部门列表 -->
<select id="getAllDepartment" resultType="java.util.List">
SELECT * FROM department
</select>
</mapper>
正确代码:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.wu.employee.mapper.IDepartmentMapper">
<!-- 查看部门列表 -->
<select id="getAllDepartment" resultType="com.wu.employee.beans.Department">
SELECT * FROM department
</select>
</mapper>
版权声明:本文为qq_32106647原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。