mybatis动态sql
Posted 吃饭睡觉打逗逗
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mybatis动态sql相关的知识,希望对你有一定的参考价值。
这种写法会报错:order by #{queryCondition.sort} #{queryCondition.order}
运行错误:
2017-07-03 14:49:40.868:WARN::Nested in org.springframework.jdbc.BadSqlGrammarException: <|### Error querying database. Cause: java.sql.SQLSyntaxErrorException: ORA-01745: 无效的主机/绑定变量名|<|### The error may exist in file [D:\project5\workspace\ytb_mb\bin\cn\newtest\ytb\mybatis_mapper\TestMapper.xml]<|### The error may involve cn.newtest.ytb.mapper.TestMapper.getTestInfo-Inline<|### The error occurred while setting parameters<|### SQL: select * from ( select A.*,rownum rn from test A order by ? ? ) B where b.rn between 10 and 10+10<|### Cause: java.sql.SQLSyntaxErrorException: ORA-01745: 无效的主机/绑定变量名||; bad SQL grammar []; nested exception is java.sql.SQLSyntaxErrorException: ORA-01745: 无效的主机/绑定变量名|:
java.sql.SQLSyntaxErrorException: ORA-01745: 无效的主机/绑定变量名|
将#改成$即可解决:order by ${queryCondition.sort} ${queryCondition.order}
以上是关于mybatis动态sql的主要内容,如果未能解决你的问题,请参考以下文章