grails 学习(二)

整合cur,并添加数据库模板切换

 

    def edit = {
  //获取当前上下文目录
  def ctx = request.contextPath
  
  //获取模板路径
  def initTemplet = new Templet()
  
  //设置当前对应的模板文件
  def templetPagePath = "/admin/templet/edit"
 
  //拼合到完整的模板路径
  def templetPath = templetService.getPath() + initTemplet.pageRoot + templetPagePath
   
  //传递到模板的数据
  def model = [ctx:ctx, initTemplet:initTemplet, templetPagePath:templetPagePath]
  
  //根据传参实例化domain
  def entity = new Templet(params)
   
  //当有传有id时,读取数据
  if(params.id != null && params.id != ""){
   def loadEntity = Templet.get( params.id )

         if(loadEntity) {
          loadEntity.properties = params
          
          entity = loadEntity;
         }
  }
  
  //当为post时,并检证数据输入没有错误时,持久化数据
  if(request.method == 'POST' && !entity.hasErrors() && entity.save()){
   if(entity.isDefault)
    templetService.setDefault(entity.id)
   
         flash.message = "entity.saved"
  }
  
  //增加需传递到模板的数据
  model.put('entity',entity)
  
  //载入模板并传递数据
  render(template:templetPath, model:model)
 }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值