首页 > 代码库 > mybatis动态sql

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