Spring Hql distinct Query查询多个字段以对象形式返回

来源:互联网 发布:淘宝米乐麻麻代购真假 编辑:程序博客网 时间:2024/05/16 06:48
@Query("select distinct rs.country,rs.language  from ResourceBundle rs" )List getLanguageAndCountry();

 我们这样写的话返回的是Object[]数组。现在想让她返回ResourceBundle。需要改写成:

@Query("select distinct new ResourceBundle(rs.country,rs.language)  from ResourceBundle rs" )List<ResourceBundle> getLanguageAndCountry();
 

这个时候domain必须要有一个构造方法:

public ResourceBundle(String country,String language){setCountry(country);setLanguage(language);}
原创粉丝点击