hibernate jdbpTemplate 转型的好东东

List<?> list = daoUtil.getSession(false).createSQLQuery(bf.toString()).setResultTransformer(Transformers.aliasToBean(MTVO.class)).setParameter("userId", userId).list();



protected ParameterizedBeanPropertyRowMapper resultBeanMapper(Class clazz) {
return ParameterizedBeanPropertyRowMapper.newInstance(clazz);
}



public Object findForObject(final String sql,Class clazz,Map parameters){
try{
Assert.hasText(sql,"sql语句不正确!");
Assert.notNull(clazz,"集合中对象类型不能为空!");
if(parameters!=null){
return jdbcTemplate.queryForObject(sql, resultBeanMapper(clazz), parameters);
}else{
return jdbcTemplate.queryForLong(sql, resultBeanMapper(clazz));
}
}catch (Exception e) {
return null;
}
}

你可能感兴趣的:(sql,Hibernate)