LoginController.groovy
package nvts.sample
import grails.converters.*
class LoginController {
static LoginService loginService
def index() {
render "Sample"
}
def getall() {
def user = User.list()
render user as JSON
}
}
第一个名为index()
的方法是呈现字符串值,但getall()
方法不呈现JSON值。
def user = User.list()
URI
/sample/login/index
Class
groovy.lang.MissingPropertyException
Message
No such property: User for class: nvts.sample.LoginController
User
是我的域类,由逆向工程师创建:
User.groovy
package sample
class User {
String emailAddress
String userPasswd
String payrollId
String posLoginId
String firstName
String lastName
String designation
String dept
String loginName
String nric
Date dateofbirth
String phyAddr1
String phyAddr2
String phyAddr3
String phyCity
String phyState
String phyCountryCode
String phyPostalCode
String postalAddr1
String postalAddr2
String postalAddr3
String postalCity
String postalState
String postalCountryCode
String postalPostalCode
String telephone
String handphone
String altEmail
String createdBy
Date dateCreated
String updatedBy
Date dateUpdated
String userMenu
String emailAddress_1
String altEmail_1
String createdBy_1
Date dateCreated_1
Date dateUpdated_1
String firstName_1
String lastName_1
String loginName_1
String payrollId_1
String phyAddr1_1
String phyAddr2_1
String phyAddr3_1
String phyCity_1
String phyCountryCode_1
String phyPostalCode_1
String phyState_1
String posLoginId_1
String postalAddr1_1
String postalAddr2_1
String postalAddr3_1
String postalCity_1
String postalCountryCode_1
String postalPostalCode_1
String postalState_1
String updatedBy_1
String userMenu_1
String userPasswd_1
static mapping = {
id name: "emailAddress", generator: "assigned"
version false
}
static constraints = {
emailAddress maxSize: 45
userPasswd maxSize: 45
payrollId nullable: true, maxSize: 20
posLoginId nullable: true, maxSize: 10
firstName maxSize: 45
lastName nullable: true, maxSize: 45
designation nullable: true, maxSize: 50
dept nullable: true, maxSize: 50
loginName nullable: true, maxSize: 45
nric nullable: true, maxSize: 10
dateofbirth nullable: true
phyAddr1 nullable: true, maxSize: 50
phyAddr2 nullable: true, maxSize: 50
phyAddr3 nullable: true, maxSize: 50
phyCity nullable: true, maxSize: 50
phyState nullable: true, maxSize: 50
phyCountryCode nullable: true, maxSize: 10
phyPostalCode nullable: true, maxSize: 10
postalAddr1 nullable: true, maxSize: 50
postalAddr2 nullable: true, maxSize: 50
postalAddr3 nullable: true, maxSize: 50
postalCity nullable: true, maxSize: 50
postalState nullable: true, maxSize: 50
postalCountryCode nullable: true, maxSize: 10
postalPostalCode nullable: true, maxSize: 10
telephone nullable: true, maxSize: 20
handphone nullable: true, maxSize: 20
altEmail nullable: true, maxSize: 50
createdBy nullable: true, maxSize: 45
dateCreated nullable: true
updatedBy nullable: true, maxSize: 45
dateUpdated nullable: true
userMenu nullable: true
emailAddress_1 maxSize: 45
altEmail_1 nullable: true, maxSize: 50
createdBy_1 nullable: true, maxSize: 45
dateCreated_1 nullable: true
dateUpdated_1 nullable: true
firstName_1 maxSize: 45
lastName_1 nullable: true, maxSize: 45
loginName_1 nullable: true, maxSize: 45
payrollId_1 nullable: true, maxSize: 20
phyAddr1_1 nullable: true, maxSize: 50
phyAddr2_1 nullable: true, maxSize: 50
phyAddr3_1 nullable: true, maxSize: 50
phyCity_1 nullable: true, maxSize: 50
phyCountryCode_1 nullable: true, maxSize: 10
phyPostalCode_1 nullable: true, maxSize: 10
phyState_1 nullable: true, maxSize: 50
posLoginId_1 nullable: true, maxSize: 10
postalAddr1_1 nullable: true, maxSize: 50
postalAddr2_1 nullable: true, maxSize: 50
postalAddr3_1 nullable: true, maxSize: 50
postalCity_1 nullable: true, maxSize: 50
postalCountryCode_1 nullable: true, maxSize: 10
postalPostalCode_1 nullable: true, maxSize: 10
postalState_1 nullable: true, maxSize: 50
updatedBy_1 nullable: true, maxSize: 45
userMenu_1 nullable: true
userPasswd_1 maxSize: 45
}
}
答案 0 :(得分:1)
我认为您错过了User.groovy
课程中LoginController.groovy
课程的导入?
import sample.User