【发布时间】:2017-01-20 02:07:28
【问题描述】:
我的 Grails 3.2.3 应用程序在端口 9000 上运行,我正在向 URL /api/mail/getUnreadCount 发出 GET 请求,但我收到该 URL 的 404 错误。
我的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)
}
}
【问题讨论】:
-
您是否尝试将 '/' 添加到 '/api/mail/getUnreadCount' 使其看起来像
/api/mail/getUnreadCount/ -
是的,我试过了,但问题仍然存在
-
我认为问题在于您的 grails 应用程序没有在 9000 端口上正常运行。点击 localhost:9000 检查您是否能够打开 grails 主页。如果它正在工作,那么它是否显示您的 mail 控制器?
-
是的,localhost:9000 工作正常,即使我正在访问索引操作,它也工作正常。我正在点击localhost:9000/api/mail 之类的 URL,它正在工作,它正在显示来自 mailController 的列表
-
那么问题是什么?您是说 localhost:9000/api/mail 正在工作,但 localhost:9000/api/mail/getUnreadCount 正在抛出 404?那么一定是打字错误。
标签: grails grails-3.0