gpt4 book ai didi

mysql - 为什么我的 mysql 查询在 JPA 中不起作用?

转载 作者:行者123 更新时间:2023-11-29 09:49:13 25 4
gpt4 key购买 nike

@Query(value = "select * from employee where ? = ?", nativeQuery = true)
public List<Employee> getEmployees(String key, String value);

员工结构为

Id

Age

Name

当我用("Age",21)调用getEmployees时,我得到的列表长度为零。在控制台中查询显示为

select * from employee where ? = ?

最佳答案

使用 JPQL 进行自定义查询

public List getEmployees(String key, String value) 
{

Query query = (Query) entityManager.createQuery("from Employee where " + key + " = " + value);
return query.getResultList();
}

关于mysql - 为什么我的 mysql 查询在 JPA 中不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55115758/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com