我正在使用Spring JPA框架和Hibernate的实现。 我在A 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()
返回列表,如[['hotel',1],['travel',2]]而不是List<Platform>
。非常感谢任何人给我一些建议!
答案 0 :(得分: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,'%')