maven web项目 findAll
findAll 查询全部的数据
他返回的是数据库中这类在数据库表中所有字段的集合
一行的搜所有字段 就是一个对象
在查询操作是没有事务回滚的
因为他是获取数据到页面进行显示
只要接受到页面过来的查询条件
并且查询条件只有一个查询语句
不会有多条查询语句
public List<Company> findAll() {
SqlSession sqlSession = null;
try{
//1.获取SqlSession
sqlSession = MapperFactory.getSqlSession();
//2.获取Dao
CompanyDao companyDao = MapperFactory.getMapper(sqlSession, CompanyDao.class);
//3.调用Dao层操作
return companyDao.findAll();
}catch(Exception e){
throw new RuntimeException(e);
}finally {
//记录日志
try {
TransactionUtil.close(sqlSession);
} catch (Exception e) {
e.printStackTrace();
}
}
}
注意: //3.调用Dao层操作
return companyDao.findAll();
这里调用的是dao接口的findAll 方法 是查询全部信息