SpringBoot JPA只取部分字段

方法一:

@Query("SELECT t.resolution from AndroidDeviceInfoEntity as t where t.partitionDate BETWEEN :startDate and :endDate")
    List<String> findByResolutionAndPartitionDateBetween(Date startDate, Date endDate, Pageable pageable);

方法二:

//通过构造函数赋值
public interface AndroidDeviceInfoEntityRepository extends JpaRepository<AndroidDeviceInfoEntity, String>{

    @Query("select new com.xx.xx.AndroidDeviceInfoEntity(t.deviceId, t.certNo, t.mobile )" +
            " from AndroidDeviceInfoEntity as t where t.deviceId =:deviceId")
    List<AndroidDeviceInfoEntity> findByDeviceId(String deviceId);
}
如果觉得我的文章对你有用,请随意赞赏