Java实现List转List

Java实现List转List<实体类>

@Override
	public List listByProperties(int start, int number) throws Exception {
		String sql = "select * from (SELECT "
				+ "decrypt_des(s.ddatetime, 'szmb#1601') ddatetime,"
				+ "decrypt_des(s.obtid, 'szmb#1601') obtid,"
				+ "decrypt_des(s.wd2df, 'szmb#1601') wd2df,"
				+ "decrypt_des(s.t, 'szmb#1601') t,"
				+ "decrypt_des(s.p, 'szmb#1601') p,"
				+ "decrypt_des(s.hourr, 'szmb#1601') hourr "
				+ "FROM t_LocalObtMind s) order by ddatetime desc ";
		Query query = em.createNativeQuery(sql.trim());
		query.setFirstResult(start);
		query.setMaxResults(number);
		List list = null;
		List list2 = new ArrayList(); 
		try{
			list = query.getResultList();
	        	for (int i = 0; i < list.size(); i++) {  
	        		LocalObtMind localObtMind = new LocalObtMind();  
	            		Object[] obj = (Object[])list.get(i); 
	            		localObtMind.setDdatetime(obj[0].toString());
	            		localObtMind.setObtid(obj[1].toString());
	            		localObtMind.setWd2df(obj[2].toString());
	            		localObtMind.setT(obj[3].toString());
	            		localObtMind.setP(obj[4].toString());
	            		localObtMind.setHourr(obj[5].toString());
	            		list2.add(localObtMind);  
	        	} 	
		}catch(Exception e){
			e.printStackTrace();
		}
		return list2;
	} 
  

你可能感兴趣的:(Java)