【发布时间】:2020-10-04 02:31:44
【问题描述】:
我正在尝试使用 JPA 存储库中的查询从我的 sql 表中提取单个字符串。我有一个存储库、服务和控制器类。我的存储库查询看起来像
@Query(value = "SELECT title FROM table_name WHERE subject = term;", nativeQuery = true)
String getTitleBySubject(String term);
我的服务方法是这样的
public String getTitleBySubject(String term) {
String title = (String) repo.getTitleBySubject(term);
return title;
}
我的控制器调用是
service.getTitleBySubject("subject");
为什么返回null?这将打印到控制台
【问题讨论】:
标签: spring-boot jpa