如何只接受grails中的post变量 [英] How to only accept post variables in grails

查看:97
本文介绍了如何只接受grails中的post变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的控制器中,我只想接受POST变量,而不是GET变量。就我所知,Grails对POST和GET没有任何区别,尽管request方法可以通过request.method来检查,但我只想特别接受POST参数。如何去做呢?对不起,如果我听起来太天真了,我刚刚开始使用Groovy和Grails以及我在PHP中的背景。 解决方案

allowedMethods 是用于



即从文档:

  class PersonController { 
// action1可以通过POST
调用// action2没有限制
// action3可以通过POST或DELETE
调用staticMethods = [action1:'POST ',
action3:['POST','DELETE']]
def action1 = {...}
def action2 = {...}
def action3 = {...}
}


In my controller, I want to accept only POST variables, not the GET Variables. Grails doesn't make any distinction between POST and GET, as far as I know, though the request method can be checked via request.method, but I want to specifically only accept POST parameters. How to go about it? Sorry, if I sound too naive, I have just started groovy and grails with my background in PHP.

解决方案

Isn't this what the allowedMethods block is for

ie from the documentation:

class PersonController {
  // action1 may be invoked via a POST
  // action2 has no restrictions
  // action3 may be invoked via a POST or DELETE
  static allowedMethods = [action1:'POST',
                           action3:['POST', 'DELETE']]
  def action1 = { … }
  def action2 = { … }
  def action3 = { … }
}

这篇关于如何只接受grails中的post变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆