search

Home  >  Q&A  >  body text

java - mybatis这个方法单元测试,总是错误

《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《
@Test
public void insertUserTest() throws IOException{
String resource = "SqlMapConfig.xml";
InputStream inputStream = Resources.getResourceAsStream(resource);
SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
SqlSession sqlSession = sqlSessionFactory.openSession();
User user = new User();
user.setAddress("寿光");
user.setBirthday(new Date());
user.setSex("1");
user.setUsername("隋伟");
sqlSession.insert("test.insertUser", user);
sqlSession.commit();
sqlSession.close();
}
《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《

insert into user(id,username,birthday,sex,address) value(#{id},#{username},#{birthday},#{sex},#{address})

一运行就说sources not found

伊谢尔伦伊谢尔伦2812 days ago591

reply all(3)I'll reply

  • 怪我咯

    怪我咯2017-04-17 14:42:06

    Check whether the UserMapper.xml file is loaded in SqlMapConfig.xml:



    Look again, I didn’t write anything wrong in the mapping file~

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-04-17 14:42:06

    Has your mapper file been configured?

    reply
    0
  • 大家讲道理

    大家讲道理2017-04-17 14:42:06

    Has the data source been configured?
    Has jdbc been integrated into mybatis?

    reply
    0
  • Cancelreply