Java实现List<Object>转List<实体类>

Java实现List<Object>转List<实体类>

@Override
	public List<LocalObtMind> 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<Object> list = null;
		List<LocalObtMind> list2 = new ArrayList<LocalObtMind>(); 
		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;
	}


©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页