@Service
@Transactional
public class PromotionServiceImpl implements PromotionService {
@Autowired
private PromotionRepository promotionRepository;
@Override
public void save(Promotion promotion){
promotionRepository.save(promotion);
}
@Override
public Page<Promotion> findPageData(Pageable pageable){
return promotionRepository.findAll(pageable);
}
@Override
public PageBean<Promotion> findPageData(int page,int rows){
Pageable pageable = new PageRequest(page-1,rows);
Pahe<Promotion> pageData = promotionRepository.findAll(pageable);
//封装到Page对象
PageBean<Promotion> pageBean = new PageBean<Promotion>();
pageBean.setTotalCount(pageData.getTotalElements());
pageBean.setPageData(pageData.getContent());
return pageBean;
}
@Override
public Promotion findById(Integer id){
return promotionRepository.findOne(id);
}
@Override
public void updateStatus(Date date){
promotionRepository.updateStatus(date);
}
}
dao持久层PromotionRepository代码:
public interface PromotionRepository extends JpaRepository<Promotion,Integer>{
@Query("update Promotion set sratus='2' where endDate<? and status='1'>")
@Modifying
void updateStatus(Date now);
}