2009-12-22 40 views
0

我試圖將值「1」傳遞給Grails標記。然而,結果是一個49的整數值 - 「1」的ascii值。我如何將其轉換爲Groovy中的適當值?在Groovy中將Ascii轉換爲Int函數

+0

這將有助於發佈代碼,因爲你的問題是幾乎可以肯定的語法。 – noah 2010-01-13 19:57:48

回答

1

實際上,String上有一個「toInteger()」函數。

0

要添加到傑克BeNimble的評論,如果你正在使用1.2(發行版的情況例外),你也有空安全轉換爲int(即params.int(「值」),它會做

Release Notes

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 [email protected], @[email protected], @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') 
+0

我怎麼能有這樣的功能,INT()或長期()params對象爲全球在外打工? – Luccas 2011-04-01 05:07:45

+0

它與您如何定義增值稅有關。使用def的 不會使其成爲全球 由於某種原因,不使用def也可以使用 或者你可以寫出所有類似於java類的東西並且有字段。然後,元類的東西將只是假設在你創建了一個類的實例後訪問它們所需要的方法 – branchgabriel 2012-05-04 19:23:41