BeanUtils.setProperty 应用

BeanUtils.setProperty 简单用法

 

	public void getOverTime() throws Exception{
		Session session = getHibernateTemplate().getSessionFactory().getCurrentSession();
		Query query = session.createSQLQuery("select distinct(workid) workid  from work");
		List<BigInteger> list = query.list();
		String deletesql = "delete from overwork";
		session.createSQLQuery(deletesql).executeUpdate();	
		for (BigInteger workid : list){
			Overwork overwork = new Overwork();
			BeanUtils.setProperty(overwork,"workid", workid); 
			int month_length = Util.getDaysOfMonth(C_YEAR + "/" + getSuitableStr(C_MONTH));
			for (int i = 1; i <= month_length; i++){
				String day = C_YEAR + "/" + getSuitableStr(C_MONTH) + "/" + i;
				String quer = "from Work where workid = " + workid + " and (worktime between '"+ day + OVERSTART + "' and '"+ day + DAYEND +"')";
				List<Work> list_1 = getHibernateTemplate().find(quer);
				if (list_1.size() > 0){
					Timestamp total_over = list_1.get(0).getWorktime();
					for (Work work : list_1){
						if (work.getWorktime().compareTo(total_over) > -1){
							total_over = work.getWorktime();
						}
					}
					SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//
					String end = df.format(total_over);
					String day1 = getSuitableStr(i);
					String begin = C_YEAR + "-" + getSuitableStr(C_MONTH) + "-" + day1 + OVERSTART;
					String time = getTimeSpace(begin, end);
					BeanUtils.setProperty(overwork,"o" + i, time); 
					
				} else {
					BeanUtils.setProperty(overwork,"o" + i, "");
				}
			}
			overworkDAO.save(overwork);
		}
	}

 

你可能感兴趣的:(BeanUtils)