The following example of use the sent methods provided by the grails letter plugin listed in this book 。
sendMail {
to "foo@example.org"
subject "Registration Complete"
body view:"/foo/bar", model:[user:new User()]
}
I understand that the code within {} is a closure that is passed to sendMail as a parameter. I also understand that to
, subject
and body
are method calls.
我试图说明实施发送邮件方法的守则所希望的是什么,而我最好的猜测就是这样:
MailService {
String subject
String recipient
String view
def model
sendMail(closure) {
closure.call()
// Code to send the mail now that all the
// various properties have been set
}
to(recipient) {
this.recipient = recipient
}
subject(subject) {
this.subject = subject;
}
body(view, model) {
this.view = view
this.model = model
}
}
这是否合理,或者我是否失踪? 尤其是,在关闭时使用的方法(to
,subject
,one
),必然是同sendmail
相同的类别成员?
Thanks, Don