MyBatis org.apache.ibatis.binding.BindingException
程序员文章站
2022-03-30 23:39:23
关于MyBatis org.apache.ibatis.binding.BindingException: Type class cn.xdl.entity.UserTB is not known to the MapperRegistry 异常解决目录结构如下Mapper代码如下(示例):package cn.xdl.dao;import java.util.List;import org.apache.ibatis.annotations.Delete;import org.apa...
关于MyBatis org.apache.ibatis.binding.BindingException: Type class cn.xdl.entity.UserTB is not known to the MapperRegistry 异常解决
目录结构如下
Mapper代码如下(示例):
package cn.xdl.dao;
import java.util.List;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import cn.xdl.entity.User;
public interface UserTBMapper {
public void insert(User user);
@Delete("delete usertb where id=#{id}")
public void delete(@Param("id")int id);
public void update(User user);
public User findById(int id);
public List<User> findAll();
}
测试类代码如下(示例):
package cn.xdl.test;
import java.io.IOException;
import java.io.Reader;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Test;
import cn.xdl.dao.UserTBMapper;
import cn.xdl.entity.UserTB;
public class UserTBTest {
@Test
public void test() throws IOException{
SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder();
Reader reader = Resources.getResourceAsReader("sqlmap-config.xml");
SqlSessionFactory factory = builder.build(reader);
SqlSession session = factory.openSession();
UserTB userDao = session.getMapper(UserTB.class);
/*userDao.delete(1003);
session.commit();*/
System.out.println(session);
}
}
总结
结果检查发现在测试类中在第22行中有问题
更改后问题解决
本文地址:https://blog.csdn.net/qq_41442866/article/details/111939940