2016-04-13 96 views
1

我正在使用Spring JPA框架与Hibernate的实现。 我宣布象下面这样一个BaseRepository查询:BaseRepository查询实体列表对象数组的返回列表

@NoRepositoryBean 
public interface BaseRepository<T, ID extends Serializable> extends PagingAndSortingRepository<T, ID>, QueryDslPredicateExecutor<T> { 
    @Query("select e.id,e.name from #{#entityName} e where e.state=1 and e.name like CONCAT(:name,'%')") 
    List<T> findIdAndNameByNameStartingWith(@Param("name") String name); 
} 

而在一个控制器使用

@RequestMapping("/list/byName") 
    public HttpApiResponse findAllByNameLike(@RequestParam(defaultValue = "") String name) { 
     List<Platform> platforms = platformRepository.findIdAndNameByNameStartingWith(name); 
     return HttpApiResponse.doSuccess(platforms); 
    } 

但是当我调试,我发现findIdAndNameByNameStartingWith()返回列表,例如[[ '酒店',1],[ 'travel',2]]而不是List<Platform>。任何人都可以给我一些建议,非常感谢!

回答

0

返回结果是什么你问

select e.id,e.name from #{#entityName} e where e.state=1 and e.name like CONCAT(:name,'%')

尝试改变

select e from #{#entityName} e where e.state=1 and e.name like CONCAT(:name,'%')

+0

下更改查询到'选择e ...'可以工作,但我不希望JPA检索该表中的所有字段,因为该接口调用频率最高,某些列存储大数据。 – BilboDai

相关问题