需要帮助,Grails mongodb如果大于,否则如果大于

时间:2012-10-01 21:14:36

标签: grails if-statement

我有一点问题,不知道+灰发。

我不太了解gsp,groovy,grails等。但是情况如下:

例如,如果我从mongodb获得的数字大于4.5,我需要显示图像。

我尝试过很多不同的东西:

                    <g:if test="${profil.punkte >0.1}">
                    <img src="${resource(dir: 'images', file: '1_5.gif')}" alt="gesamtbewertung in sternen" >
                    </g:if>
                    <g:elseif test="${profil.punkte >1.49}">
                    <img src="${resource(dir: 'images', file: '2_5.gif')}" alt="gesamtbewertung in sternen" >
                    </g:elseif>
                    <g:elseif test="${profil.punkte >2.49}">
                    <img src="${resource(dir: 'images', file: '3_5.gif')}" alt="gesamtbewertung in sternen" >
                    </g:elseif>
                    <g:elseif test="${profil.punkte >3.49}">
                    <img src="${resource(dir: 'images', file: '4_5.gif')}" alt="gesamtbewertung in sternen" >
                    </g:elseif>
                    <g:elseif test="${profil.punkte >4.49}">
                    <img src="${resource(dir: 'images', file: '5_5.gif')}" alt="gesamtbewertung in sternen" >
                    </g:elseif>

我尝试了很多不同的语法来解决这个问题,但它不会起作用。在上面的版本中,它始终显示1_5.gif

“profil.groovy”中的条目看起来很......像:

class Profil {
ObjectId id
...
...
double punkte
}

mongodb的JSON中的条目如下:

 "punkte": 4.3,

我只需要输入$ {profil.punkte}并获得4.3渲染。

希望即使我的英语被打破,你也能理解我的问题。 我将在笔记本电脑上进行后空翻以解决问题!

1 个答案:

答案 0 :(得分:2)

嗯,你需要做出更好的条件。你看到4.3大于0.1吗?然后它总是输入第一个if和nothing。

在您的条件中添加一些限制,它会起作用。

相关问题