問題描述:
在練習mybaties的時候前幾個查詢功能都沒有問題,寫到後來添加不同的查詢的時候前面的所有測試都過不了,全部出現這個錯誤,在.m2裡面刪除重新導入該包也無法解決,求好人賜教!
org.apache.ibatis.exceptions.PersistenceException:
相關代碼如下:
SqlSessionFactory factory;
@Before
public void init() throws Exception{
//初始化MyBatis
Reader reader = Resources.getResourceAsReader("SqlMapConfig.xml");
SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder();
factory = builder.build(reader);
}
@Test
public void testFindAllUsers() {
SqlSession session = factory.openSession();
System.out.println(session);
//SelectList(id)方法執行查詢語句,其中id是在Mapper文件中SQL語句的ID
List list = session.selectList("findAllUsers");
for (User user : list) {
System.out.println(user);
}
session.close();
}
找到十一點二十,終於自己找出了問題,自己回復慶祝一下
配置文件SqlMapConfig.xml,不小心寫了兩個mappers標簽,淚奔...
<mappers>
<mapper resource="mappers/UserMapper.xml" />
</mappers>
<mappers>
<mapper resource="mappers/UserMapper.xml"></mapper>
<mapper resource="mappers/EmployeeMapper.xml"></mapper>
</mappers>