本篇文章主要介绍了"spring-mybatis myBatis系列之二:以接口方式交互数据",主要涉及到spring-mybatis方面的内容,对于MySql感兴趣的同学可以参考一下:
myBatis系列之一:搭建开发环境是采用SqlSession的通用方法并强制转换的方式,存在着转换安全的问题: User user = (Us...
或在初始化语句中加入:
sqlSessionFactory.getConfiguration().addMapper(IUserMapper2.class);
如下所示:
@BeforeClass
public static void initial() {
try {
reader = Resources.getResourceAsReader("Configuration.xml");
sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
sqlSessionFactory.getConfiguration().addMapper(IUserMapper2.class);
} catch (IOException e) {
log.error("Error thrown while reading the configuration: {}", e);
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e) {
log.error("Error thrown while closing the reader: {}", e);
}
}
}
}
3.相应修改上面的测试方法