grails

今天在网上到了一篇文章,是关于grails的,说grails在国外很流行,但在中国得5年之后 才会流行起来,听着挺不错的,一直都是用grails做开发的。
今天在基于前人的基础上,把grails的 mail 插件搞清楚 了,而且还做了一个小小的项目。下面听我一一到来。
我根据别人的文章,跟着它做了一遍,最好一直抱501的错误,后来仔细看了一下错误代码,发现在少了一个东西,也就说明那文章是有错误的。
1、首先创建自己的项目 create-app MGMail
2、发邮件得有几个必须的内容吧?
[color=red]String emailAdd [/color] //邮件地址
[color=red]String title [/color] //主题
[color=red]String content [/color] //内容
[color=red]Date sendTime[/color] //发送时间
所以创建一个域类 create-domai-class com.cn.SendMail,在该类下面添加如下内容:
[color=red]String emailAdd [/color] //邮件地址
[color=red]String title [/color] //主题
[color=red]String content [/color] //内容
[color=red]Date sendTime[/color] //发送时间

//数据库字段
[color=red]static mapping = { content type:'text' }

static constraints = {
emailAdd(maxLength:200,blank:false,email:true)
title(maxLength:200,blank:false)
content(blank:false)
}[/color]
//在插入数据之前 执行当前操作
[color=red]def beforeInsert = {
sendTime = new Date()
}[/color] 好了,域类创建好了,现在就是创建controll类了
3、创建controll类 create-controll com.cn.SendMail ,直接修改里面的save action,如下:
def save = {
def sendMailInstance = new SendMail(params)
if(!sendMailInstance.hasErrors()&&sendMailInstance.save()){
//如果保存数据成功,就发送到保存的邮箱地址中

sendMail{
[color=red]to sendMailInstance.emailAdd [/color]//发送到邮箱地址
[color=green]from "tao.fu@softvan.com.cn"[/color] [color=red]subject sendMailInstance.title [/color] //邮件主题

[color=red] body sendMailInstance.content [/color]//邮件内容
//如果邮件包含html代码的话,请使用下面的语句
//html sendMailInstance.content //邮件内容
render "发送完毕……"
}

} else {
render(view: "create", model: [sendMailInstance: sendMailInstance])
}
}
大家注意绿色部分的内容…………
4、现在创建
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值