sql映射到vo,count as
需要映射为BigInteger
,否则会报错
示例: sql
select s.user_id as userId, s.user_name as userName,s.user_photo as userPhoto, count(1) as score from voluntary_activity_signup s where s.is_apply= 0 and s.delete_flag = 0 group by s.user_id order by score desc
对应的class
@Data
public class InfoT {
private String userName;
private String userId;
private String userPhoto;
private BigInteger score;
}
源码是如何处理的
Query q = em.createNativeQuery(sql);
q.unwrap(SQLQuery.class).setResultTransformer(Transformers.aliasToBean(clazz));
List resultList = q.getResultList();
return resultList;
参考