这是 Controller 的代码:
package kaf82.portal
import javax.xml.parsers.DocumentBuilderFactory
class PersonsController {
def personList = []
String personsFile = new File('media/data/personsData.xml').text
def allpersons () {
def persons = new XmlParser().parseText(personsFile)
[persons: persons]
}
def currentperson () {
int id=params.id.toInteger()
getPersons()
[currentperson=personList.get(id-1)]
}
def getPersons() {
def builder = DocumentBuilderFactory.newInstance().newDocumentBuilder()
def inputStream = new ByteArrayInputStream(personsFile.bytes)
def root = builder.parse(inputStream).documentElement
def persons = root.childNodes
(0..<persons.length).each{ processPerson(persons.item(it)) }
...
我正在使用Grails 2.4.4。
这是stacktrace
Line | Method
->> 17 | currentperson in PersonsController.groovy
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 198 | doFilter in PageFragmentCachingFilter.java
| 63 | doFilter . . in AbstractFilter.java
| 53 | doFilter in GrailsAnonymousAuthenticationFilter.java
| 49 | doFilter . . in RequestHolderAuthenticationFilter.java
| 82 | doFilter in MutableLogoutFilter.java
| 1142 | runWorker . . in java.util.concurrent.ThreadPoolExecutor
| 617 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run . . . . . in java.lang.Thread
最佳答案
假设第17行是:
[currentperson=personList.get(id-1)]
您没有正确初始化 map (请参阅groovy docs)。正确的解决方案是:
[currentperson: personList.get(id-1)]
否则,编译器中应该有一个变量
currentperson
,您要为其分配一个值。关于grails - 没有这样的属性:class的currentperson:kaf82.portal.PersonsController,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29611785/