redirect(action:"hasOrder",params:[stuNo:myStudentNo, order:unDone.id.toString()])
def retAsJson = [:]retAsJson = [ "ret":0,"msg":message(code: 'vippay.createOid.error')
]render retAsJson as JSON※ 如果是函数中间需跳转返回,后面需要加上 return
x = df.parse(字符串)
计算前一天
import org.apache.commons.lang.time.DateUtils;
def date = DateUtils.addDays( params.createDate, -1 )
String s = Integer.toString(i);
def ret = [:]
ret << [param1:"Success"]
ret << [param2:param2, flg :2]
return retList<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
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 {}
mList << [(it.name2+it.name) : it.score]
取值时
courseTestId.get(course)
mList[it.name2 + it.name]