我在使用rawsql查询时遇到了一个问题。下面是一个简单的例子。
Finder<Long, Test> finder= new Finder<>(Test.class);
String query = "SELECT t.ID AS t_id, t.NAME as t_name, (SELECT CASE WHEN t.NAME = :name THEN 1 ELSE 0 END) AS sort_priority FROM test ORDER BY sort_priority";
RawSql raw = RawSqlBuilder.parse(query)
.columnMapping("t_id", "id")
.columnMapping("t_name", "name")
.columnMappingIgnore("sort_priority")
.create();
Query<Test> testQuery = finder.query().setRawSql(raw).setParameter("name", "Test1");
但是当我执行这个查询时,我得到一个错误:
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 ':name THEN 1 ELSE 0 END) AS sort_priority FROM test ORDER BY sort_priorit' at line 1
如果我用的话?没有命名参数,一切正常。但是,我可以通过同时保留named parameter和case-when子句来修复它吗?
暂无答案!
目前还没有任何答案,快来回答吧!