2017-01-18 13 views
0

我的Grails 3.2.3应用程序在端口9000上运行,我正在做一个GET请求到URL /api/mail/getUnreadCount, m得到一个404错误的URL。

URLMapping.groovy有:

get "/api/$controller(.$format)?"(action: "index") 
get "/api/$controller/$id(.$format)?"(action: "show") 

"/api/$controller/$action?/$id?(.$format)?" { 
    constraints { 
     // apply constraints here 
    } 
} 

而且帮助我,怎样才能让Grails的URL映射日志?

更新1

class MailController { 

    static allowedMethods = [index: "GET", getUnreadCount: "GET"] 
    ..... 
    ....... 
    def getUnreadCount() { 
     User currentUserInstance = springSecurityService.getCurrentUser() 
     List counts = userService.getUnreadCounts(currentUserInstance) 
     respond(counts) 
    } 
} 
+0

是否尝试添加'/'到'/ api/mail/getUnreadCount',因此它看起来像'/ api/mail/getUnreadCount /' – mic4ael

+0

是的,我试过了,但仍然存在问题 –

+0

我认为问题在于Grails应用程序在9000端口上运行不正常。请检查您是否可以通过点击** http:// localhost:9000 **来打开grails主页。如果它正在工作,那么它是否显示你的**邮件**控制器? –

回答

1

预计,你有意见getUnreadCount.gsp/mail目录,以获得输出respond

..并为你的代码提供的,如果你没有任何看法,你应该得到Error 500不是404.

在你的代码中,把

格式:[ 'XML', 'JSON']

或明确地提及视图

观点: “showCount”

或尝试render方法代替

更新

顺便说一句,请删除

get "/api/$controller/$id(.$format)?"(action: "show") 

当你点击/ API /邮件/ getUnreadCount,这个映射导致$id = getUnreadCount,而不必在你的控制器,它产生错误的任何行动show