【问题标题】:Spring Data JPA passing dynamic column names as parameter to querySpring Data JPA 将动态列名作为参数传递给查询
【发布时间】:2019-06-17 14:37:38
【问题描述】:

我有表 emp,其中包含 emp_name、emp_desc、emp_age、emp_country、emp_pincode 列。

我正在使用 Spring data Jpa 进行数据库操作。

 @Repository
 public interface EmpRepository extends JpaRepository<Emp, String> {}

和empRepository.findAll();从 emp 表中触发 select *。

但我有如下要求

客户端应用程序会将列名作为参数传递给方法中的选择,我只想获取 Jpa 中的那些而不是 Findall()。

如何在 Jpa 中实现这一点?

【问题讨论】:

  • 您不需要在从 Spring Datas Repository 接口扩展的存储库上添加 @Repository 注释。

标签: spring spring-data-jpa spring-data microservices


【解决方案1】:

试试这个 根据 emp_name 获取员工详细信息 empRepository.findByEmpName(String empName);

【讨论】:

    猜你喜欢
    • 2018-05-04
    • 1970-01-01
    • 1970-01-01
    • 2017-06-23
    • 2018-11-14
    • 2019-12-09
    • 2011-01-30
    • 2021-02-06
    相关资源
    最近更新 更多