Grails开源框架Note
2015-09-17 17:10
411 查看
redirect(action:"hasOrder",params:[stuNo:myStudentNo,
order:unDone.id.toString()])
1、身份验证springSecurityService
case :取得用户 Id(教师 || 学生 ObjectId) def myStudentId = springSecurityService.currentUser.teacherstudentId
case :取得用户 身份权限 def roles = SpringSecurityUtils.authoritiesToRoles(springSecurityService.authentication.authorities)
验证用户身份 if(roles.contains("ROLE_CHECKER")){……}
Role 包括 ROLE_USER ROLE_CHECKER ROLE_ADMIN ROLE_TEACHER ROLE_STUDENT
ROLE_MANAGER ROLE_SUPER ROLE_SWITCH_USER ROLE_EDITOR
case :取得用户 userName def username = springSecurityService.currentUser.username
取得教师信息 userManagerService.getTeacherInstance
2、Ajax请求,返回页面
def retAsJson = [:]
retAsJson = ["ret":0,
"msg":message(code:'vippay.createOid.error')
]
render retAsJson as JSON
※ 如果是函数中间需跳转返回,后面需要加上 return
3、check出现错误后,return
flash.message = message(code: 'vippay.roles.error')
// messages_zh_CN.properties 文件中写明错误提示消息
case A :需跳转至错误画面 redirect(controller:"message",
action:"error") return
case B :需跳至某个gsp页面,gsp<body>内需写明:
4、日期格式化
导包 : import java.text.SimpleDateFormat;
定义 : defdf = new SimpleDateFormat("yyyy-MM-dd")
: defdf = new SimpleDateFormat("yyyy-MM-dd
HH:mm:ss")
EG.. x = df.format(日期格式)
x = df.parse(字符串)
计算前一天
import org.apache.commons.lang.time.DateUtils;
def date
= DateUtils.addDays( params.createDate, -1 )
5、String 与 Integer、int 的转换
1 int i
= Integer.valueOf(str).intValue();
int i = Integer.parseInt(str);
2 Integer integer=Integer.valueOf(str);
3 String s = String.valueOf(i);
String s = Integer.toString(i);
String s = "" + i;
6、A函数调用B函数,需要返回>1个返回值
B函数
def ret
= [:]
ret << [param1:"Success"]
ret << [param2:param2, flg :2]
return ret
A函数
def result
= ……
result.param1 ……
7、后台往前台传List
List<Product> list = paymentService.getVIPProductList(type)
List<Product> proList = new ArrayList<Product>()
list?.each{
proList << [pid:it.pid,
name:it.name,
price:it.price,
intro:it.intro]
}
result << [stuNo:myStudentNo, proList:proList.sort{it.pid} as JSON]
8、数字合法性验证
Pattern pattern =Pattern.compile("[0-9]*")
if(!pattern.matcher(pid).matches())
或
if(!params.studentNo ||
!params.studentNo.matches("[\\d]+"))
9、sort方法
opList.sort{a,b
->
b.opDate <=> a.opDate
}
opList.sort{it.opDate}
10、后台组合combobox
case A:传递固定值
def contrastList
= [];
contrastList << ['id':"eq",'text':"等于"];
contrastList << ['id':"neq",'text':"不等于"];
render contrastList as JSON
case B :
11、前后台传List
Js:
var rows = [{key1:1},{key1:2}]
var para= JSON.stringify(rows)
Controller:
def x
= params.para
def x1
= new JsonSlurper().parseText(x)
12、页面超时避免出错【身份验证】
import grails.plugins.springsecurity.Secured;
@Secured(['ROLE_TEACHER','ROLE_ADMIN','ROLE_CHECKER'])
class BOT900503Controller
{}
13、Map中Key为变量时操作
def mList
=[:]
mList << [(it.name2+it.name)
: it.score]
取值时
courseTestId.get(course)
mList[it.name2 + it.name]
转载于:/article/1900252.html
redirect(action:"hasOrder",params:[stuNo:myStudentNo,
order:unDone.id.toString()])
1、身份验证springSecurityService
case :取得用户 Id(教师 || 学生 ObjectId) def myStudentId = springSecurityService.currentUser.teacherstudentId
case :取得用户 身份权限 def roles = SpringSecurityUtils.authoritiesToRoles(springSecurityService.authentication.authorities)
验证用户身份 if(roles.contains("ROLE_CHECKER")){……}
Role 包括 ROLE_USER ROLE_CHECKER ROLE_ADMIN ROLE_TEACHER ROLE_STUDENT
ROLE_MANAGER ROLE_SUPER ROLE_SWITCH_USER ROLE_EDITOR
case :取得用户 userName def username = springSecurityService.currentUser.username
取得教师信息 userManagerService.getTeacherInstance
2、Ajax请求,返回页面
def retAsJson = [:]
retAsJson = ["ret":0,
"msg":message(code:'vippay.createOid.error')
]
render retAsJson as JSON
※ 如果是函数中间需跳转返回,后面需要加上 return
3、check出现错误后,return
flash.message = message(code: 'vippay.roles.error')
// messages_zh_CN.properties 文件中写明错误提示消息
case A :需跳转至错误画面 redirect(controller:"message",
action:"error") return
case B :需跳至某个gsp页面,gsp<body>内需写明:
4、日期格式化
导包 : import java.text.SimpleDateFormat;
定义 : defdf = new SimpleDateFormat("yyyy-MM-dd")
: defdf = new SimpleDateFormat("yyyy-MM-dd
HH:mm:ss")
EG.. x = df.format(日期格式)
x = df.parse(字符串)
计算前一天
import org.apache.commons.lang.time.DateUtils;
def date
= DateUtils.addDays( params.createDate, -1 )
5、String 与 Integer、int 的转换
1 int i
= Integer.valueOf(str).intValue();
int i = Integer.parseInt(str);
2 Integer integer=Integer.valueOf(str);
3 String s = String.valueOf(i);
String s = Integer.toString(i);
String s = "" + i;
6、A函数调用B函数,需要返回>1个返回值
B函数
def ret
= [:]
ret << [param1:"Success"]
ret << [param2:param2, flg :2]
return ret
A函数
def result
= ……
result.param1 ……
7、后台往前台传List
List<Product> list = paymentService.getVIPProductList(type)
List<Product> proList = new ArrayList<Product>()
list?.each{
proList << [pid:it.pid,
name:it.name,
price:it.price,
intro:it.intro]
}
result << [stuNo:myStudentNo, proList:proList.sort{it.pid} as JSON]
8、数字合法性验证
Pattern pattern =Pattern.compile("[0-9]*")
if(!pattern.matcher(pid).matches())
或
if(!params.studentNo ||
!params.studentNo.matches("[\\d]+"))
9、sort方法
opList.sort{a,b
->
b.opDate <=> a.opDate
}
opList.sort{it.opDate}
10、后台组合combobox
case A:传递固定值
def contrastList
= [];
contrastList << ['id':"eq",'text':"等于"];
contrastList << ['id':"neq",'text':"不等于"];
render contrastList as JSON
case B :
11、前后台传List
Js:
var rows = [{key1:1},{key1:2}]
var para= JSON.stringify(rows)
Controller:
def x
= params.para
def x1
= new JsonSlurper().parseText(x)
12、页面超时避免出错【身份验证】
import grails.plugins.springsecurity.Secured;
@Secured(['ROLE_TEACHER','ROLE_ADMIN','ROLE_CHECKER'])
class BOT900503Controller
{}
13、Map中Key为变量时操作
def mList
=[:]
mList << [(it.name2+it.name)
: it.score]
取值时
courseTestId.get(course)
mList[it.name2 + it.name]
转载于:/article/1900252.html
相关文章推荐
- HDU 1022 Train Problem I(用栈模拟火车出入,看能否由初始顺序到达目标顺序)
- Boost库安装与使用 http://blog.csdn.net/cybertan/article/details/5770227
- 开源C/C++网络库比较 http://blog.csdn.net/langeldep/article/details/6976120
- ubuntu重啟網卡提示"Job failed while stopping"解決方法!【参考别人的信息】
- aidl理解
- 打开IDEA时报错“Failed to create JVM: error code -6”
- 【Code Forces 320A】【二进制拆分】Raising Bacteria 细胞繁殖 每天倍增
- CodeForces 579A - Raising Bacteria
- 音乐播放器-MainFragment分析1
- UVA-818 Cutting Chains (位压缩+暴力搜索)
- 严重: StandardServer.await: create[8005]:
- Failed to create a 'System.Type' from the text ' ' in wpf(无法从文本创建类型)
- AIX加入能telnet远程连接方法的帐户
- The service ‘xxx’ configured for WCF is not registered with the Autofac container
- .NET基础--Contains用法
- Raising Bacteria
- 百度mall首探(百度商城http://mall.baidu.com)
- Send email from dynamics ax
- LeetCode219:Contains Duplicate II
- ECSHOP后台SQL查询提示错误 this sql May contain UPDATE,DELETE,TRUNCATE,ALTER,DROP,FLUSH,INSERT