借助弹簧数据,您可以削减中间人并简单地定义
public interface Idsonly { Integer getId(); String getOtherId();}并使用本机查询,例如;
@Query(value = "Id, OtherId from TestTable where CreationDate > ?1 and Type in (?2)", nativeQuery = true) public Collection<IdsOnly> findEntriesAfterDate(Date creationDate, List<Integer> types);
查看https://docs.spring.io/spring-
data/jpa/docs/current/reference/html/#projections



