<!--定期维护物资可用状态--><updateid="updateStatus">
update supplies set status=#{status} where id=#{id}
</update><selectid="list"resultType="com.cnooc.emergency.entity.Supply">
select * from supplies
</select>
3、service
/**
* 定期维护物资状态
* @param id
* @param status
* @return
*/booleanupdateStatus(String id,String status);
List<Supply>list();
4、serviceImpl,加注解@Scheduled
/**
* 查询所有
* @return
*/@Overridepublic List<Supply>list(){return supplyMapper.list();}/**
* 定时修改物资状态
*/@Scheduled(cron ="0 0 9 * * ?")publicvoidTask(){
Date date =newDate();long timeNow = date.getTime();
List<Supply> list = supplyMapper.list();for(int i =0; i < list.size(); i++){//获取遍历id
String id = list.get(i).getId();// 获取设置过期时间并转为long型long time = list.get(i).getExpirationTime().getTime();//比较过期时间 如果过期时间小于当前时间,状态改为已过期if(time < timeNow){
supplyMapper.updateStatus(id,"已过期");}}}