beetlsql报错“请指定Sql类型“的解决方案
生活随笔
收集整理的這篇文章主要介紹了
beetlsql报错“请指定Sql类型“的解决方案
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
解決
beetlsql使用dao自定義SQL語句時,有些情況下會報錯“請指定Sql類型”,這時需要在dao方法上加上@SqlStatement注解。
例如:
@SqlResource("kn.xxxx") @Repository public interface xxxxDao extends BaseMapper<xxxx> {@SqlStatement(type = SqlStatementType.SELECT)List<KnCategory> findParentList(@Param(value = "id") String id); }原因
beetlsql執(zhí)行自定義的sql時,會根據(jù)sql語句開頭的字母,判斷當前執(zhí)行的是Select、Update還是Delete。
SQL如下:
with recursive t as (select * from xxxx where 1=1@if(!isEmptyObject(id!)){and id = #id#@}union allselect c.* from xxxxc join t on t.parent_id = c.id ) select * from t我這邊寫的是一個遞歸查詢,sql用with開頭,而不是常規(guī)的select,導致識別不了就報錯了。所以加上@SqlStatement(type = SqlStatementType.SELECT),表示當前語句按照Select執(zhí)行即可。
總結
以上是生活随笔為你收集整理的beetlsql报错“请指定Sql类型“的解决方案的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: idea编辑器关闭重复代码检查
- 下一篇: Elasticsearch 常见的DSL