gpt4 book ai didi

grails - 闭包返回其引用/指针而不是返回值

转载 作者:行者123 更新时间:2023-12-02 14:57:59 25 4
gpt4 key购买 nike

当我输出一个属性时,我想我得到了闭包的引用/指针,而不是期望的返回值。

例如,对于以下属性:${g.goalsAgainstAverage}:

<td header="stathdr5 stathdr${g.leagueId} stathdrgt${g.leagueId}_${g.gameTypeId}">${g.goalsAgainstAverage}</td>

将输出:
<td header="stathdr5 stathdr1 stathdrgt1_3">com.mgs.StatService$__tt__getSeasonStats_closure10$_closure24$_closure25@61df269d</td>

这是生成值的服务(请参阅 calcGoalsAgainstAverage):
import grails.transaction.Transactional

@Transactional
class StatService {

def serviceMethod() {

}

def getSeasonStats(Long userId, Long seasonId){

def seasonRaw = Game.createCriteria().list{
...
}

def seasonStats = seasonRaw
.groupBy { it.leagueId }
.collect { leagueId, records ->
[
...
gameTypes: records.collect {
[
...
goalsAgainstAverage: {calcGoalsAgainstAverage(it.secondsPlayed, it.minutesPlayed, it.gameInMinutes, it.goalsAgainst)}
]
}
]
}
return seasonStats
}

double calcGoalsAgainstAverage(int secondsPlayed, int minutesPlayed, int gameInMinutes, int goalsAgainst){
...
}
}

最佳答案

您要返回封包...

可以更改:

goalsAgainstAverage: {calcGoalsAgainstAverage(it.secondsPlayed, it.minutesPlayed, it.gameInMinutes, it.goalsAgainst)}


goalsAgainstAverage: calcGoalsAgainstAverage(it.secondsPlayed, it.minutesPlayed, it.gameInMinutes, it.goalsAgainst)

或者,改变
${g.goalsAgainstAverage}


${g.goalsAgainstAverage()}

关于grails - 闭包返回其引用/指针而不是返回值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35756488/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com