使用Spring Data JPA nativeQuery时如何用参数值替换表名 [英] How to replace table name with value from parameter while using Spring Data JPA nativeQuery

查看:856
本文介绍了使用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.

这篇关于使用Spring Data JPA nativeQuery时如何用参数值替换表名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆