0

我有一个关于 grails 应用程序的问题。我有一个控制器,它在服务器端做了很多工作,并且可能需要几分钟才能完成它的任务。我担心如果用户在代码运行时点击刷新,它会尝试再次运行代码。我将如何防止这种情况。下面是一些伪代码

 def refreshDb = {      
    requeryDataBase()
}

  public void requeryDatabase(){

    ....some long process here
  }

那么,如果 requeryDataBase() 已经在运行,我将如何防止它运行?

感谢您的帮助或见解!杰森

4

2 回答 2

3

您应该查看使用 Web 请求提交表单令牌。它存储一次性令牌,因此不允许多次提交并且可以检测到。有关更多详细信息,请参阅有关处理重复提交的 grails 框架文档

于 2011-07-28T00:54:41.280 回答
1

如果您希望多个用户能够使用控制器,则可以使用会话对象,如下所示。

  public void requeryDatabase(){
if (session['queryRunning']==false) {
   session['queryRunning']=true
    ....some long process here
session['queryRunning']=false //set to false so the user can execute the controller again
}
 else {
   //Put code to notify the user to be pacient here
}
  }
于 2011-07-27T23:49:58.053 回答