mybatis错误: Invalid bound statement (not found) 怎么解决-问答-阿里云开发者社区-阿里云

开发者社区> 问答> 正文

mybatis错误: Invalid bound statement (not found) 怎么解决

小旋风柴进 2016-03-03 11:51:58 15703

0.问题说明:
我是一名菜鸟,最近使用spring-mvc ,spring,mybatis框架
这两天出现一个错误一直搞不定,心好累,恳请前辈帮帮忙

  1. 异常
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.misscandy.inter.UserMapper.findAllUsers
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:978)
    org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:868)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
    org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
    org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)

2.我的配置文件

<!-- spring和MyBatis完美整合,不需要mybatis的配置映射文件 -->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="mapperLocations" value="classpath:com/misscandy/mapper/*.xml" />
    </bean>

    <!-- 按指定包和注解扫描 Mapper/DAO -->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="sqlSessionFactory" ref="sqlSessionFactory" />
        <property name="basePackage" value="com.misscandy.inter" />
        <property name="annotationClass" value="com.misscandy.mapper.Mapper" />
    </bean>

3.接口
UserMapper.java

package com.misscandy.inter;

import java.util.Vector;

import com.misscandy.entity.User;
import com.misscandy.mapper.Mapper;


@Mapper
public interface UserMapper {
    void addUser(User user);
    //void deleteUser(User user);
    //void updateDept(User user);
    User findUserByName(String userName);
    Vector<User> findAllUsers();
    //List<Map<String, Object>> findValue();
    //List<DeptVO> findValues();
}

4.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">
    <!-- namespace -->
<mapper namespace="com.misscandy.inter.UserMapper">

    <!-- @1 resultMap
         @2 resultMap=""-->
    <resultMap id="userResultMap" type="com.misscandy.entity.User">
        <id property="userId" column="user_id" javaType="Integer" jdbcType="INTEGER" />
        <result property="userName" column="user_name" javaType="String"
            jdbcType="VARCHAR" />
        <result property="password" column="password" javaType="String"
            jdbcType="VARCHAR" />
        <result property="sex" column="sex" javaType="Integer"
            jdbcType="INTEGER" />
        <result property="age" column="age" javaType="Integer"
            jdbcType="INTEGER" />
        <result property="type" column="type" javaType="Integer"
            jdbcType="INTEGER" />
        <result property="lastLoginTime" column="last_login_time"
            javaType="Date" jdbcType="DATE" />
        <result property="imageSrc" column="image_src" javaType="String"
            jdbcType="VARCHAR" />
    </resultMap>

    <select id="findUserByName" parameterType="String" resultMap="userResultMap">
        <![CDATA[
        select user_id,user_name,image_src,age,sex,type from users where user_name = #{userName}
        ]]>
    </select>

    <select id="findAllUsers" resultMap="userResultMap">
        <![CDATA[
        select user_id,user_name,age,sex,type from users
        ]]>
    </select>

    <insert id="addUser" parameterType="com.misscandy.entity.User">
        <![CDATA[
        insert into users 
        (user_name,password,sex,age,type)
        values
        (#{userName},#{password},#{sex},#{age},1)
        ]]>
    </insert>

</mapper>
noti错误 state错误 invalid错误bound invalidmybatis错误 invalid错误
分享到
取消 提交回答
全部回答(1)
  • 小旋风柴进
    2019-07-17 18:51:10

    检查一下你的配置文件中,但是你的UserMapper.xml看上去是在com.misscandy.inter文件夹下面,是不是?

    0 0
开发与运维
使用钉钉扫一扫加入圈子
+ 订阅

集结各类场景实战经验,助你开发运维畅行无忧

相似问题
最新问题