Grails 1.2.1的奇怪UrlMappings行为

时间:2010-03-25 14:56:39

标签: grails url-mapping

我在SpringSource Tools Suite 2.3.2中创建了一个Grails(1.2.1)应用程序,这是我的UrlMappings.groovy:

class UrlMappings {
    static mappings = {
      "/$controller/$action?/$id?"{
       constraints {
    // apply constraints here
    }
   }

      "/broadcasters/setInterval" { //cause a 404
            controller = "broadcaster"
            action = "setRefreshInterval"
      }

      "/broadcasters/online/$id?" { //this one is OK
       controller = "broadcaster"
       action = "listOnlineBroadcasters"
      }
      "/broadcasters/$id?" { //this one is OK
       controller = "broadcaster"
       action = "listAllBroadcasters"
      }
      "/" (controller: "login", action:"auth")
      "/logout" (controller: "logout")
   "500"(view:'/error')
   "404"(view:'/404')
 }
}

这是我的控制器

package xxx.yyy.controllers

import org.codehaus.groovy.grails.plugins.springsecurity.Secured

@Secured(['ROLE_ADMIN'])
class BroadcasterController {

 def broadcasterService
 static defaultAction = "listAllBroadcasters"

    def listOnlineBroadcasters = {
        ...
    }

    def listAllBroadcasters = {
        ...
    }

 def setRefreshInterval = {
  ...
 }
}

当我访问网址 / broadcasters / setInterval 时,我有404正常或ajax请求。我还写了一个简单的单元测试来检查我的UrlMappings:

class GSMUrlMappingTests extends GrailsUrlMappingsTestCase {
    void testUrlMapping() {
        assertUrlMapping ("/broadcasters/setInterval", controller: "broadcaster", action: "setRefreshInterval")
    }
}

测试失败了!这是Grails 1.2.1的错误还是我错过了什么? 这是我用过的插件

plugins.acegi=0.5.2
plugins.debug=1.0.2
plugins.hibernate=1.2.1
plugins.jdbc-pool=0.1
plugins.tomcat=1.2.1

1 个答案:

答案 0 :(得分:0)

class UrlMappings { static mappings = { "/$controller/$action?/$id?"{ constraints { // apply constraints here } }

已关闭。 其他映射需要在

之内