CodeController.groovy
上传用户:steveyhw
上传日期:2019-05-13
资源大小:307k
文件大小:3k
- class CodeController {
- def index = { redirect(action:list,params:params) }
- // the delete, save and update actions only accept POST requests
- def allowedMethods = [delete:'POST', save:'POST', update:'POST',initAllCodes:['GET','POST']]
- def list = {
- if(!params.max) params.max = 10
- [ codeList: Code.list( params ) ]
- }
- def show = {
- def code = Code.get( params.id )
- if(!code) {
- flash.message = "code.not.found"
- flash.args = [params.id]
- flash.defaultMessage = "Code not found with id ${params.id}"
- redirect(action:list)
- }
- else { return [ code : code ] }
- }
- def delete = {
- def code = Code.get( params.id )
- if(code) {
- code.delete()
- flash.message = "code.deleted"
- flash.args = [params.id]
- flash.defaultMessage = "Code ${params.id} deleted"
- redirect(action:list)
- }
- else {
- flash.message = "code.not.found"
- flash.args = [params.id]
- flash.defaultMessage = "Code not found with id ${params.id}"
- redirect(action:list)
- }
- }
- def edit = {
- println params
- def code = Code.get( params.id )
- if(!code) {
- flash.message = "code.not.found"
- flash.args = [params.id]
- flash.defaultMessage = "Code not found with id ${params.id}"
- redirect(action:list)
- }
- else {
- return [ code : code ]
- }
- }
- def update = {
- def code = Code.get( params.id )
- if(code) {
- code.properties = params
- if(!code.hasErrors() && code.save()) {
- flash.message = "code.updated"
- flash.args = [params.id]
- flash.defaultMessage = "Code ${params.id} updated"
- redirect(action:show,id:code.id)
- }
- else {
- render(view:'edit',model:[code:code])
- }
- }
- else {
- flash.message = "code.not.found"
- flash.args = [params.id]
- flash.defaultMessage = "Code not found with id ${params.id}"
- redirect(action:edit,id:params.id)
- }
- }
- def create = {
- def code = new Code()
- code.properties = params
- return ['code':code]
- }
- def save = {
- def code = new Code(params)
- if(!code.hasErrors() && code.save()) {
- flash.message = "code.created"
- flash.args = ["${code.id}"]
- flash.defaultMessage = "Code ${code.id} created"
- redirect(action:show,id:code.id)
- }
- else {
- render(view:'create',model:[code:code])
- }
- }
- def initAllCodes = {
- def codeService = new CodeService()
- try {
- codeService.initCodes()
- } catch (Exception e) {
- log.error(e.message, e)
- }
- render(text:"DATA INITED",contentType:'text/plaintext',encoding:"GB2312")
- //render(text:"数据已经成功初期化",contentType:'text/plaintext',encoding:"UTF-8")
- }
- }