grails 查询

27 篇文章 0 订阅
3 篇文章 0 订阅

grails手册的API先粘下Mark先:

Node Description Example
betweenWhere the property value is between to distinct values
between("balance", 500, 1000)
eqWhere a property equals a particular value
eq("branch", "London")
eqPropertyWhere one property must equal another
eqProperty("lastTransaction","firstTransaction")
gtWhere a property is greater than a particular value
gt("balance",1000)
gtPropertyWhere a one property must be greater than another
gtProperty("balance","overdraft")
geWhere a property is greater than or equal to a particular value
ge("balance",1000)
gePropertyWhere a one property must be greater than or equal to another
geProperty("balance","overdraft")
idEqWhere an objects id equals the specified value
idEq(1)
ilikeA case-insensitive 'like' expression
ilike("holderFirstName","Steph%")
inWhere a one property is contained within the specified list of values note: 'in' is a groovy reserve word, we must escape it by quotes.
'in'("holderAge",[18..65])
isEmptyWhere a collection property is empty
isEmpty("transactions")
isNotEmptyWhere a collection property is not empty
isNotEmpty("transactions")
isNullWhere a property is null
isNull("holderGender")
isNotNullWhere a property is not null
isNotNull("holderGender")
ltWhere a property is less than a particular value
lt("balance",1000)
ltPropertyWhere a one property must be less than another
ltProperty("balance","overdraft")
leWhere a property is less than or equal to a particular value
le("balance",1000)
lePropertyWhere a one property must be less than or equal to another
leProperty("balance","overdraft")
likeEquivalent to SQL like expression
like("holderFirstName","Steph%")
neWhere a property does not equals a particular value
ne("branch", "London")
nePropertyWhere one property does not equal another
neProperty("lastTransaction","firstTransaction")
orderOrder the results by a particular property
order("holderLastName", "desc")
sizeEqWhere a collection property's size equals a particular value
sizeEq("transactions", 10)


def MyTrade = Trade.createCriteria()
        PagedResultList pagedResultList
        pagedResultList = MyTrade.list(max: params.max ?: 10, offset: params.offset ?: 0) {
            eq('status', 5 as byte)
            eq('returnStatus', 0 as byte)
            eq('type',12 as byte)
            gt("status",0 as byte)
            if (start != null) {
                gt("dateCreated", start)
            }
            if (end != null) {
                lt("dateCreated", end)
            }
            if (tradeCode)
            {
                eq('tradeId',tradeCode)
            }
            if(kdNum){
                List<MikuOrdersLogistics> kdlist=MikuOrdersLogistics.findAllByWlnumber(kdNum)
                if (kdlist){
                    'in'("tradeId", kdlist*.tradeId)
                }
            }
            if(userName){
                List<Logistics> logisticsesList=Logistics.findAllByContactNameLike("%"+userName+"%")
                if(logisticsesList){
                    'in'("consigneeId", logisticsesList*.id)
                }
            }
            if(isdf){
                if ("1".equals(isdf)){
                   not {
                       'in'("payType", [6 as byte,9 as byte,10 as byte])
                   }
                }
                else if("2".equals(isdf)){
                    'in'("payType", [6 as byte,9 as byte,10 as byte])
                }
            }
            if (StringUtils.isNotBlank(mobile)) {
                def logisticss = Logistics.findAllByMobile(mobile)
                Profile profile = Profile.findByMobile(mobile)
                if (profile && logisticss) {
                    or {
                        eq("buyerId", profile.id)
                        'in'("consigneeId", logisticss*.id)
                    }
                } else if (profile) {
                    eq('buyerId', profile.id)
                } else if (logisticss) {
                    "in"('consigneeId', logisticss*.id)
                } else {
                    eq("id", -1L)
                }
            }
            if (totalFeeOp && targetTotalFee)
            {
                List<Trade> tlist=Trade.findAllByStatus(4 as byte)
                List<Trade> moneyList=new ArrayList<Trade>()
                tlist.each {
                    Trade tobj->
                        if (totalFeeOp.equals(">") && tobj.totalFee>targetTotalFee)
                        {
                            moneyList.add(tobj)
                        }
                        else if (totalFeeOp.equals("<") && tobj.totalFee<targetTotalFee)
                        {
                            moneyList.add(tobj)
                        }
                        else if(totalFeeOp.equals("=") && tobj.totalFee==targetTotalFee)
                        {
                            moneyList.add(tobj)
                        }
                }
                if (moneyList.size())
                {
                    "in"('id', moneyList*.id)
                }
                else{
                    eq("id", -1L)
                }
            }
            order('id', 'desc')
            order('lastUpdated', 'desc')
        }


PagedResultList pagedResultList
        pagedResultList=NineLabPitemLog.createCriteria().list(max: params.max ?: 10, offset: params.offset ?: 0){
            order('lastUpdated', 'desc')
            if(prodType)
            {
                eq("prodType",Byte.parseByte(prodType))
            }
            if(status)
            {
                eq("status",Byte.parseByte(status))
            }
            if(itemName)
            {
                ilike("itemName","%" + itemName + "%")
            }
            if(itemCode)
            {
                eq("code",itemCode)
            }
        }


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值