[Grails] GORM

fenglin_Java 2012-03-28
我有一个User domain
class User {
	/*
	 CREATE TABLE  `dc_dev`.`userdata` (
	 `UserID` int(11) NOT NULL AUTO_INCREMENT,
	 `ContactID` int(11) DEFAULT '-1',
	 `Email` varchar(70) DEFAULT NULL,
	 `Password` varchar(250) DEFAULT NULL,
	 `NoOfDomains` int(11) DEFAULT NULL,
	 `Uniques` int(11) DEFAULT NULL,
	 `Top10` text,
	 `Active` tinyint(1) DEFAULT '0',
	 `ConfirmationPending` tinyint(1) DEFAULT '1',
	 `CreationTime` datetime DEFAULT NULL,
	 `ConfirmationCode` varchar(40) DEFAULT NULL,
	 `PrivilegeNum` int(11) DEFAULT '0' COMMENT '0:normal user, 1:admin low (limited admin), 2:admin middle, 3:admin:high, 4:(not defined), 5:super',
	 `DomainPageSize` int(11) DEFAULT '10',
	 `MainPageIndex` int(11) DEFAULT '0',
	 `APIUserHandle` varchar(10) DEFAULT 'dcu00003',
	 `LastVisitTime` datetime DEFAULT NULL,
	 PRIMARY KEY (`UserID`)
	 ) ENGINE=InnoDB AUTO_INCREMENT=464 DEFAULT CHARSET=latin1
	 */
	String email
	String password
	Integer noOfDomains
	Integer uniques
	String top10
	Boolean active
	Boolean confirmationPending
	Date creationTime
	String confirmationCode
	Integer privilegeNum
	Integer domainPageSize
	// MainPageIndex
	String apiUserHandle
	Date lastVisitTime

	static mapping = {
		table "userdata"
		id(column: "UserID")
		email(column: "Email")
		password(column: "Password")
		noOfDomains(column: "NoOfDomains")
		uniques(column: "Uniques")
		top10(column: "Top10", sqlType:"TEXT")
		active(column: "Active")
		confirmationPending(column: "ConfirmationPending")
		creationTime(column: "CreationTime")
		confirmationCode(column: "ConfirmationCode")
		privilegeNum(column: "PrivilegeNum")
		domainPageSize(column: "DomainPageSize")
		apiUserHandle(column: "APIUserHandle")
		lastVisitTime(column: "LastVisitTime")
		version false
	}

	static constraints = {
		email email: true, size: 6..100, unique: true
		password size: 3..30

	}
}

一个UserController
class UserController {
    def scaffold = User
    def userDataDao

    def login() {
    }

    def authenticate() {
//        def user = userDataDao.getUserByEmail(params.email)
        def user = User.findByEmail("test@dc.com")
        println user.email
        if (user) {
            session.user = user
            flash.message = "Welcome! ${user.email}"
            redirect(controller: "home", action: "index")
        } else {
            flash.message = "Sorry! ${params.email} can't find"
            redirect(action: "login")
            return false
        }
    }

    def logout() {
        session.user = null
        redirect(controller: "home", action: "index")
    }
}

为什User.findByEmail("") 这个方法提示missingMethod阿,log里面看已经动态产生find方法了阿?为什么不能用呢?
fenglin_Java 2012-03-30
没人用动态finders吗?为什么我用不了呢?是不是要装什么插件呢?
Global site tag (gtag.js) - Google Analytics