gpt4 book ai didi

mysql - Spring Boot从url给出的mysql表中获取数据

转载 作者:行者123 更新时间:2023-11-29 10:32:14 24 4
gpt4 key购买 nike

我想创建简单的应用程序来搜索特定表中的一些数据。我有一个数据库并且可以连接到它。另外,当我对表名称进行硬编码时,效果很好。但我想制作这样的网址:

/demo/{table}/{author}

我应该给出具体的表格,例如。 “喜剧”,接下来我设置作者姓名,例如。 “史密斯”。

我的书库:

@Query(value = "SELECT * FROM :table WHERE author = :author",
nativeQuery=true)
public List<Book> findByAuthor(@Param("author") String author, @Param("table") String table);

但是没有成功。我遇到错误:

 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''comedy' WHERE author = 'Smith'' at line 1

它将 ' 添加到查询中。有办法删除吗?是否可能或者我需要将所有内容放在一张表中?干杯:)

最佳答案

我没有查过,但是查询SQL中的变量似乎只能用于插入带引号的值,而不能用于插入像表名这样不带引号的标识符。

关于mysql - Spring Boot从url给出的mysql表中获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47186285/

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