使用Spring Data JPA nativeQuery时如何用参数值替换表名
问题描述:
像这样:
public interface XXXRepository extends CrudRepository<XXX, Integer> {
@Query(value = "select * from ?1 where ...", nativeQuery = true)
List<XXX> findByXXX(String tableName, ...);}
它给出了带有on代码的MYSQL语法错误. 语法错误表明SQL中的表名用'"括起来.
It gives MYSQL syntax error with upon codes. The syntax error shows that the table name in the SQL is surrounded with "'".
答
这是不可能的.仅在where子句中允许使用参数.
This is not possible. Parameters are only allowed in the where clause.