我有查询(总是返回列表有1个SysAutoId

@Query(value = "SELECT * FROM SYSAutoID WHERE RefTypeCategory = ?1 AND BranchID = ?2 ", nativeQuery = true)
List<SysAutoId> findSpecific(Integer refTypeCategory, Integer branchId);


我想创建一个像

@Query(value = "SELECT * FROM SYSAutoID WHERE RefTypeCategory = ?1 AND BranchID = ?2 ", nativeQuery = true)
SysAutoId findSpecific(Integer refTypeCategory, Integer branchId);


返回一个实体,该怎么做?

最佳答案

返回类型应为Entity的Optional,因为它仅返回第一条匹配记录,请查看findById方法的语法

Optional<T> findById(ID primaryKey)




@Query(value = "SELECT * FROM SYSAutoID WHERE RefTypeCategory = ?1 AND BranchID = ?2 ", nativeQuery = true)
Optional<SysAutoId> findSpecific(Integer refTypeCategory, Integer branchId);

08-07 04:53