步骤1:在com.bstek.dorado.sample.standardlesson.service包中新建CompanyService.java,代码如下:
package com.bstek.dorado.sample.standardlesson.service; import java.util.Collection; import javax.annotation.Resource; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; import com.bstek.dorado.annotation.DataProvider; import com.bstek.dorado.annotation.DataResolver; import com.bstek.dorado.sample.standardlesson.dao.SlCompanyDao; import com.bstek.dorado.sample.standardlesson.entity.SlCompany; @Component public class CompanyService{ @Resource private SlCompanyDao slcompanyDao; @DataProvider public Collection<SlCompany> getCompany(){ return slcompanyDao.getAll(); } }
我们发现getCompany方法其实就是执行了其父类hibernateDao中的getAll方法,我们接下来看看hibernateDao的getAll方法源码:
@SuppressWarnings("unchecked") public List<T> getAll() { return createCriteria().list(); } public Criteria createCriteria() { return getSession().createCriteria(entityType); }
可以看出getAll方法就是根据实体对象进行查询操作。