mybatis中mappers配置问题
本帖最后由 duwei1990 于 2013-12-19 15:06:21 编辑 mybatis中mappers配置:
<mappers>
<!-- <mapper resource="com/hxtg/sqlmapper/User.xml" /> -->
<package name="com.hxtg.dao"/><!-- 用这种方式就不行了呢? -->
</mappers>
<!-- Register all interfaces in a package as mappers -->
<mappers>
<package name="org.mybatis.builder"/>
</mappers>
String resource = "Mybatis.xml";
SqlSession session = null;
try {
InputStream input = Resources.getResourceAsStream(resource);
SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(input);
session = sqlSessionFactory.openSession();
UserDao userDao = session.getMapper(UserDao.class);
List<User> users = userDao.getUserList();
for (User user : users) {
System.out.println(user.getAccountid());
}
System.out.println("SUCCESS");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
session.close();
}