说明:记录一次MyBatis错误,错误信息如下:
2024-09-01 23:13:35.369 ERROR 7860 --- [nio-9090-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.hezy.repository.UserRepository.getLists] with root causeorg.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.hezy.repository.UserRepository.getListsat org.apache.ibatis.binding.MapperMethod$SqlCommand.<init>(MapperMethod.java:235) ~[mybatis-3.5.9.jar:3.5.9]at org.apache.ibatis.binding.MapperMethod.<init>(MapperMethod.java:53) ~[mybatis-3.5.9.jar:3.5.9]at org.apache.ibatis.binding.MapperProxy.lambda$cachedInvoker$0(MapperProxy.java:108) ~[mybatis-3.5.9.jar:3.5.9]at java.base/java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1705) ~[na:na]
说DAO没有找到绑定的标签
场景
就是很普通的一次列表查询,查询某张表的所有记录,如下:
(Controller)
@GetMappingpublic List<User> getLists() {return userRepository.getLists();}
(DAO)
List<User> getLists();
(动态SQL)
<select id="getLists" resultType="java.util.List">select * from tb_user</select>
为什么会报没有找到绑定的statement
解决
resultType
返回的对象类型,应该是实体类的全限定类名,而不是List,下面这样才是对的
<select id="getLists" resultType="com.hezy.pojo.User">select * from tb_user</select>