如何在querydsl中提取StringPath值的字符串值?

时间:2015-09-18 07:46:54

标签: querydsl

我尝试运行此代码。

List<TbFrLanguageInfo> list = queryFactory.selectFrom(qTbFrLanguageInfo)
        .where( qTbFrLanguageInfo.languageSq
                .eq(   (String) (( map.get("languageSq") ==null || map.get("languageSq").equals("") ) ? qTbFrLanguageInfo.languageSq.stringValue() :map.get("languageSq"))     ) 
                .and( qTbFrLanguageInfo.languageId
                        .eq( (String) ((map.get("languageId") == null  || map.get("languageId").equals("") ) ?  qTbFrLanguageInfo.languageId.stringValue() : map.get("languageId"))) )
                .and ( qTbFrLanguageInfo.useYn.eq( (String) (( map.get("useYn")== null || map.get("useYn").equals("")) ?  qTbFrLanguageInfo.useYn.stringValue() : map.get("useYn"))   ))
                ).orderBy(qTbFrLanguageInfo.orderNo.asc()).fetch();

但我收到了错误。

Exception in thread "main" java.lang.ClassCastException: com.querydsl.core.types.dsl.StringPath cannot be cast to java.lang.String
    at com.xxx.redca.hub.admin.module.language.dao.impl.LanguageMgnDaoImpl.selectLanguageList(LanguageMgnDaoImpl.java:72)
    at com.xxx.redca.hub.admin.module.language.dao.impl.LanguageMgnDaoImpl$$FastClassBySpringCGLIB$$d2a565a4.invoke(<generated>)

更新

我试过了。

List<TbFrLanguageInfo> list = queryFactory
        .selectFrom(qTbFrLanguageInfo)
        .where(  
                qTbFrLanguageInfo.languageSq.eq(
                        ( map.get("languageSq") ==null || map.get("languageSq").equals("") ) ?  
                                qTbFrLanguageInfo.languageSq : Expressions.constant( map.get("languageSq")))      
                .and( qTbFrLanguageInfo.languageId.eq(  
                        ((map.get("languageId") == null  || map.get("languageId").equals("") ) ?  
                                qTbFrLanguageInfo.languageId : Expressions.constant(map.get("languageId"))) ))
                .and ( qTbFrLanguageInfo.useYn.eq( 
                        ( map.get("useYn")== null || map.get("useYn").equals("")) ?  
                                qTbFrLanguageInfo.useYn : Expressions.constant( map.get("useYn")))   )
                ).orderBy(qTbFrLanguageInfo.orderNo.asc()).fetch();

错误如下。我认为有解决这个问题的简单方法......

The method eq(String) in the type SimpleExpression<String> is not applicable for the arguments (Expression<capture#1-of ? extends Object>)

奇怪的是,如果我删除它,它是否正常工作? :运算符并使用如下所示的一个表达式。

qTbFrLanguageInfo.languageSq.eq(qTbFrLanguageInfo.languageSq)
qTbFrLanguageInfo.languageSq.eq( Expressions.constant( map.get("languageSq")) )

0 个答案:

没有答案