mybatis 解析 SQL Mapper Configuration 时出错

Error parsing SQL Mapper Configuration in mybatis

我在 servlet 中使用 mybatis 框架,mybatis-config.xml 文件无法找到 Student_mapper class.I 应用了所有路径,包括包名称并排除它和在我的 mybatis-config.xml 中也使用了该元素,但它没有 work.I 我仍然遇到相同的错误。

Error building SqlSession.The error may exist in SQL Mapper Configuration 
Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: java.lang.ClassNotFoundException: Cannot find class: mybatis/Student_mapper
    org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
    org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:52)
    org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:36)
    mybatis.Serv.doGet(Serv.java:49)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:626)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:733)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)

这是我的mybatis-config.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 type="mybatis.Student_mapper"
            alias="Student_mapper" />
    </typeAliases>
    <environments default="development">
        <environment id="development">
            <transactionManager type="JDBC" />
            <dataSource type="POOLED">
                <property name="driver" value="org.postgresql.Driver" />
                <property name="url"
                    value="jdbc:postgresql://localhost:5432/chitra" />
                <property name="username" value="postgres" />
                <property name="password" value="admin" />
            </dataSource>
        </environment>
    </environments>

    <mappers>

        <mapper class="mybatis/Student_mapper" />
    </mappers>
</configuration>

这是我的 Student_mapper 界面

package mybatis;

import java.util.List;
import org.apache.ibatis.annotations.*;
public interface Student_mapper 
{
   final String getAll = "SELECT * FROM STUDENT"; 
   final String getById = "SELECT * FROM STUDENT WHERE ID = #{id}";
   final String deleteById = "DELETE from STUDENT WHERE ID = #{id}";
   final String insert = "INSERT INTO STUDENT (ID,NAME, COURSE, ROLL) VALUES (#{id},#{name}, #{course}, #{roll})";
   final String update = "UPDATE STUDENT SET NAME = #{name}, COURSE = #{course}, ROLL = #{roll} WHERE ID = #{id}";
   @Select(getAll)
   @Results(value = {
      @Result(property = "id", column = "ID"),
      @Result(property = "name", column = "NAME"),
      @Result(property = "course", column = "COURSE"),
      @Result(property = "roll", column = "ROLL")
   })
   List<Student> getAll();
   

   @Select(getById)
   @Results(value = {
      @Result(property = "id", column = "ID"),
      @Result(property = "name", column = "NAME"),
      @Result(property = "course", column = "COURSE"),
      @Result(property = "roll", column = "ROLL")
   })
   Student getById(int id);
   
   @Update(update)
   void update(Student student);
   @Delete(deleteById)
   void delete(int id);
   @Insert(insert)
   //@Options(useGeneratedKeys = true, keyProperty = "id")
   void insert(Student student);
}

映射器 class 需要是有效的 Java class 名称。将您的 mybatis-config.xml 更改为以下内容:

  <mappers>
    <mapper class="mybatis.Student_mapper" />
  </mappers>