在java读取数据中 经常会用到表连接,这就需要用到java原生语句就行表连接
@
Query(value
="SELECT * FROM news INNER JOIN typ ON n.ttid=typ.tid where title LIKE CONCAT('%',:title,'%')",nativeQuery
=true)
Page
<List
<Map
>> finAllP(Pageable page
,String title
);
例如以上代码 就行表连接的时候就会报错
Unknown column
'INNER.id' in 'order clause'
如果把inner删除掉 就会报错
Unknown column
'JOIN.id' in 'order clause'
所以到这里就可以知道正确的写法了
@
Query(value
="SELECT * FROM news INNER JOIN typ ON n.ttid=typ.tid where title LIKE CONCAT('%',:title,'%')",nativeQuery
=true)
Page
<List
<Map
>> finAllP(Pageable page
,String title
);
这样就不会报错,所以可以得到一个结论,那就是就行表连接的时候,from后面的表需要一个简写 否则系统会自动认为表名后的第一个单词是你的简写,就会引起报错