我有代码。
@Repository
public class ArticlesDao {
@Autowired
private SessionFactory sessionFactory;
/**
* @param count Specifited how many article get from DB
* @param start Start offset. Default 0
* @return all get article
*/
@Transactional
public List<Article> getLastArticles(Integer count, Integer start) {
if (start == null) {
start = 0;
}
final Session currentSession = sessionFactory.getCurrentSession();
final Criteria criteria = currentSession.createCriteria(Article.class);
criteria.addOrder(Order.desc("publishedDate"));
criteria.setFirstResult(count + start);
criteria.setMaxResults(count);
return criteria.list();
}
}
和控制器
@Autowired
ArticlesDao dao;
@RequestMapping(value = "/")
public ModelAndView getHome(@RequestParam("page") int page) {
dao.getLastArticles("STH args");
}
我的问题是是否getHome()
应该注释Handler @Transactional
?