0

这是我的选择代码

QueryExpressionDSL<SelectModel>.QueryExpressionWhereBuilder sql =
                SelectDSL.select(CreativeDailyDtoDynamicSqlSupport.mallId)
                .from(CreativeDailyDtoDynamicSqlSupport.creativeDailyDto)
                .where()
                .and(Add.of(CreativeDailyDtoDynamicSqlSupport.click,CreativeDailyDtoDynamicSqlSupport.impr), IsIn.of(1L,2L,3L));

在这个查询中,我想创建像

select mall_id from creative_daily_table where (click+impr) in (1,2,3)

但它会抛出异常

### The error may exist in com/pdd/service/koduck/repository/mapper/CreativeDailyDtoMapper.java (best guess)
### The error may involve com.pdd.service.koduck.repository.mapper.CreativeDailyDtoMapper.selectMany-Inline
### The error occurred while setting parameters
### SQL: select mall_id from base_creative_daily_report_ where (ad_id + plan_id) in (?,?,?)
### Cause: java.sql.SQLException: java.lang.ClassCastException: com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr cannot be cast to com.alibaba.druid.sql.ast.SQLName
; uncategorized SQLException; SQL state [null]; error code [0]; java.lang.ClassCastException: com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr cannot be cast to com.alibaba.druid.sql.ast.SQLName; nested exception is java.sql.SQLException: java.lang.ClassCastException: com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr cannot be cast to com.alibaba.druid.sql.ast.SQLName
       org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:89)
       org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81)
       org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81)
       org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:91)
       org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:441)
       com.sun.proxy.$Proxy96.selectList(Unknown Source)
       org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:224)
       org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:147)
       org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:80)
       org.apache.ibatis.binding.MapperProxy$PlainMethodInvoker.invoke(MapperProxy.java:152)
       [...]

似乎在 mybatis 动态 sql 中不支持 cluase 的地方起作用。

有一些解决方法吗?

4

0 回答 0