hushenbin
super_bin
2014-12-15 12:22

mybatis错误:Invalid bound statement (not found)万分感谢!

30
  • mybatis

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>


  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

13条回答