我的url映射配置如下:
class UrlMappings {
static mappings = {
"/"(controller:"index")
"/$controller/$action?/$id?(.${format})?"{
constraints {
// apply constraints here
}
}
"500"(view:'/error')
////////////////////////
"/recetas"(resources:"receta",version:'1.0',namespace:'user'){
"/eventos"(resources:'evento',version:"1.0",namespace:"user")
}
}
}
此网址映射会生成此网址映射报告。
|URL Mappings Configured for Application
|---------------------------------------
Dynamic Mappings
| * | /${controller}/${action}?/${id}?(.${format)? | Action: (default action) |
| * | ERROR: 500 | View: /error |
Controller: dbdoc
| * | /dbdoc/${section}?/${filename}?/${table}?/${column}? | Action: (default action) |
Controller: evento
| GET | /recetas/${recetaId}/eventos | Action: index |
| GET | /recetas/${recetaId}/eventos/create | Action: create |
| POST | /recetas/${recetaId}/eventos | Action: save |
| GET | /recetas/${recetaId}/eventos/${id} | Action: show |
| GET | /recetas/${recetaId}/eventos/${id}/edit | Action: edit |
| PUT | /recetas/${recetaId}/eventos/${id} | Action: update |
| DELETE | /recetas/${recetaId}/eventos/${id} | Action: delete |
Controller: index
| * | / | Action: (default action) |
Controller: receta
| GET | /recetas | Action: index |
| GET | /recetas/create | Action: create |
| POST | /recetas | Action: save |
| GET | /recetas/${id} | Action: show |
| GET | /recetas/${id}/edit | Action: edit |
| PUT | /recetas/${id} | Action: update |
| DELETE | /recetas/${id} | Action: delete |
我的EventoController
package com.ar.dasding
import grails.converters.JSON;
import grails.plugin.springsecurity.annotation.Secured;
import grails.transaction.Transactional;
@Transactional(readOnly = true)
@Secured(["ROLE_ADMIN"])
class EventoController {
def index(Integer max) {
params.max = Math.min(max ?: 10, 100)
def receta = Receta.get(params.recetaID)
log.debug("Eventos para receta " + params.recetaID + ": " + receta.eventos)
render receta.eventos as JSON
}
}
recetaController工作正常,但向EventoController发出此请求返回404
Request URL:http://localhost:8080/DasDingProject/recetas/1/eventos
Request Method:GET
Status Code:404 Not Found
Request Headersview source
Accept:application/json, text/javascript, */*; q=0.01
Accept-Encoding:gzip,deflate,sdch
Accept-Language:es-ES,es;q=0.8,en;q=0.6
Connection:keep-alive
Cookie:JSESSIONID=30283EAC18BD88238A12449E825D8127; grails_remember_me=bWU6MTM5MTA4OTY5Njk3MTpmNmM3N2Q5MWU3ZTU3ZGE0OGRhZjAzNDViYzU5NDg3Yg
Host:localhost:8080
Referer:http://localhost:8080/DasDingProject/userHome
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.77 Safari/537.36
X-Requested-With:XMLHttpRequest
Response Headersview parsed
HTTP/1.1 404 Not Found
Server: Apache-Coyote/1.1
Content-Type: text/html;charset=utf-8
Content-Length: 1015
Date: Thu, 16 Jan 2014 14:04:04 GMT
问题是控制器是否可能没有实现映射到url映射中的所有操作?
提前致谢。
答案 0 :(得分:0)
我感觉网址映射的特殊性有些奇怪。
如果用以下内容替换“/ eventos”映射会发生什么:
“/ recetas / $ {recetaID} / EVENTOS”(控制器: “EVENTOS”,动作: “索引”)
本身,在'recetas'映射关闭之外