【发布时间】:2017-01-13 10:31:22
【问题描述】:
我有 spring 数据 jpa 存储库。我的实体包含主键 id int 和 ipaddress 字符串。该表一次仅包含 1 条记录,否则为空。 我如何使用 JPA 检索记录,如果找不到返回 null。
@Repository
public interface IpConfigRepository extends JpaRepository<IpConfig, Integer> {
//
IpConfig findIpConfig();
}
【问题讨论】:
-
使用
findAll()并在您的服务中自己管理空转换,或编写查询。
标签: spring-boot spring-data-jpa