grails मेल प्लगइन द्वारा प्रदान की गई SendMail विधि का उपयोग करने का निम्नलिखित उदाहरण this book में दिखाई देता है।ग्रोवी क्लोजर पैरामीटर
sendMail {
to "[email protected]"
subject "Registration Complete"
body view:"/foo/bar", model:[user:new User()]
}
मैं समझता हूँ कि भीतर कोड {} को बंद करने कि एक पैरामीटर के रूप sendmail को पारित कर दिया जाता है। मैं यह भी समझता हूं कि to
, subject
और body
विधि कॉल हैं।
मैं यह पता लगाने की क्या कोड है कि sendmail विधि को लागू करता है की तरह लग रहे हैं कोशिश कर रहा हूँ, और मेरे सर्वोत्तम अनुमान कुछ इस तरह है:
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
, body
), आवश्यक रूप से उसी वर्ग के सदस्य sendMail
के रूप में हैं?
धन्यवाद, डॉन