程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> spring-mybatis錯誤: Invalid bound statement (not found) 萬分感謝!

spring-mybatis錯誤: Invalid bound statement (not found) 萬分感謝!

編輯:編程綜合問答
mybatis錯誤: Invalid bound statement (not found) 萬分感謝!

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>


最佳回答:


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

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved