我正在尝试这样做,但我的IDE说不是预期的(然后错误说我的语法不正确)
我想这样做
@Query(value = "SELECT students.*, reports.* FROM students left join reports ON (.......) where student.id= :studentId LIMIT 1500", nativeQuery= true)
List<Object[]> findByStudentId(@Param("studentId") long studentId);
我的表格报告可能不一样,例如math_report,lab_report等......但结构相同,因此除了表格Im加入的名称之外,查询将是相同的。
检查我使用过的文档
left join ?#{reportName} ON...
,当然还要将reportName作为参数。
这会引发一个无法像这样编译的异常
知道怎么做吗?它甚至可能吗?
编辑:
当我这样做时
left join :tableName
我明白了:
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''math_report' report ON (....' at line 1
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_131]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_131]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_131]
at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_131]
at com.mysql.jdbc.Util.handleNewInstance(Util.java:425) ~[mysql-connector-java-5.1.44.jar:5.1.44]
at com.mysql.jdbc.Util.getInstance(Util.java:408) ~[mysql-connector-java-5.1.44.jar:5.1.44]
tableName的值现在是math_report