解决Error querying database. Cause: java.lang.IllegalArgumentException: Mapped Statements collection
在spring+mybatis开发中遇到如下错误
HTTP Status 500 - Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException:
type Exception report
message Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException:
description The server encountered an internal error that prevented it from fulfilling this request.
exception
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.IllegalArgumentException: Mapped Statements collection does not contain value for org.test.resources.mybatis.RouteMapper.findRoutes ### Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for org.test.resources.mybatis.RouteMapper.findRoutes org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:948) org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:827) javax.servlet.http.HttpServlet.service(HttpServlet.java:621) org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812) javax.servlet.http.HttpServlet.service(HttpServlet.java:728) org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88) org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
调查代码发现org.test.UserMapper.findUsers没有找到org.test.UserMapper.findUsers,代码userMapper.xml是已经写过的 为什么没有找到呢,
通过查找代码发现 mybatis的配置文件中userMapper.xml没有配置才会出现上述错误
<mapper resource="org/test/resources/mybatis/userMapper.xml" />路径要写正确 完整写法如下:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd"> <configuration> <typeAliases> <typeAlias alias="UserEntity" type="org.test.bean.User" /> </typeAliases> <mappers> <mapper resource="org/test/resources/mybatis/userMapper.xml" /> </mappers> </configuration> 在dao中写法,包名加类名要注意写对 getSqlSession().selectList("org.test.resources.mybatis.UserMapper.findUsers"); userMapper.xml的写法:
<?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="org.test.resources.mybatis.UserMapper"> <resultMap type="UserEntity" id="userResultMap"> <id property="id" column="id" /> <result property="name" column="name" /> </resultMap> <select id="findUsers" resultType="UserEntity" resultMap="userResultMap"> select id ,name from tb_users </select> </mapper>
顶
踩
相关文章:
- lass org.springframework.beans.BeanWrapperImpl can
- 解决 org.mybatis.spring.MyBatisSystemException: ne
- 解决 Exception in thread "main" java.lang.Illega
- 解决 WebSocketHandlerMapping#0': Cannot resolve r
- java spring后台如何解决跨域请求 No 'Access-Contro
- spring 配置事务不起作用原因 service层事务无效
- spring mvc 获取HttpServletRequest HttpServletRespo
- Cause: org.xml.sax.SAXParseException: The content
- 解决 Caused by: org.springframework.beans.BeanInst
- javax.net.ssl.SSLException: java.lang.RuntimeExcep