日期:2014-05-18 浏览次数:20724 次
<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();
}