Grails开源框架Note
2015-08-10 16:39
399 查看
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>内需写明:
![](http://img.blog.csdn.net/20150810164234780?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
![](file:///C:/Users/byxpc60/AppData/Local/YNote/data/736063593@qq.com/185717557fdc498a8dc616fbdc334735/a1e79994a40a40adb8267c21a1c5b4eb.jpg)
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
![](file:///C:/Users/byxpc60/AppData/Local/YNote/data/736063593@qq.com/185717557fdc498a8dc616fbdc334735/a1e79994a40a40adb8267c21a1c5b4eb.jpg)
![](http://img.blog.csdn.net/20150810164320734?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
case B :
![](http://img.blog.csdn.net/20150810164328519?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
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]
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>内需写明:
![](file:///C:/Users/byxpc60/AppData/Local/YNote/data/736063593@qq.com/185717557fdc498a8dc616fbdc334735/a1e79994a40a40adb8267c21a1c5b4eb.jpg)
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
![](file:///C:/Users/byxpc60/AppData/Local/YNote/data/736063593@qq.com/185717557fdc498a8dc616fbdc334735/a1e79994a40a40adb8267c21a1c5b4eb.jpg)
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]
相关文章推荐
- hdu1532Drainage Ditches 最大流模板水题
- Maven工程产生Jar时Main-Class和Class-Path的配置文件
- HOJ 13383 The Big Painting 二维字符串hash
- HN OJ 13375 Flowery Trails (spfa的路径遍历)
- Run-Time Check Failure #2 - Stack around the variable 'XX‘ was corrupted 解决方法
- 小米手机真机测试 waitingforDebugge 不动了
- hdu 1702 ACboy needs your help again!
- rails 2.3.8 对应的Gemfile内容
- 利用 gnuplot 绘制时间序列图 http://blog.csdn.net/liyuanbhu/article/details/8497582
- retain
- [单调栈] poj 3250 Bad Hair Day
- Gym - 100625J Jailbreak 最短路+搜索
- hyundai-wia
- grails中简单分页
- INSTALL_FAILED_MEDIA_UNAVAILABLE 错误解决
- hduoj 13375 Flowery Trails
- grails 常用技巧
- 矩阵hash + KMP - UVA 12886 The Big Painting
- SparkException: Failed to get broadcast (TorrentBroadcast)
- 1086.Tree Traversals Again