![](/img/trans.png)
[英]groovy.langMissingMethodException in calling groovy function
[英]Ascii to Int function in Groovy
我試圖將值“ 1”傳遞給Grails標記。 但是,結果是49的整數-“ 1”的ascii值。 如何在Groovy中將其轉換為適當的值?
實際上,字符串上有一個“ toInteger()”函數。
要補充一下Jack BeNimble的評論,如果您使用的是1.2(即將發布),則還可以使用將null安全的轉換器轉換為int(即params.int('value'),該轉換器可以
從發行說明 。
Convenient, null safe converters in params and tag attributes
New convenience methods have been added to the params object and tag attrs objects that allow the easy, exception safe and null safe conversion of parameters to common types:
def total = params.int('total')
There are methods for all the common base types such as int@, @long@, @boolean and so on. There is a special converter called list that always returns a list for cases when dealing with one or many parameters of the same name:
def names = params.list('names')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.