Grails 如何为REST和基于浏览器的交互创建URL映射
我希望从控制器中获得以下功能,并且匹配的REST支持这些功能:Grails 如何为REST和基于浏览器的交互创建URL映射,grails,url-mapping,Grails,Url Mapping,我希望从控制器中获得以下功能,并且匹配的REST支持这些功能: 创造一种颜色 根据id获取特定颜色 获取所有颜色 我有以下URL方案: "/$controller/$action?/$id?"{ constraints { // apply constraints here } } "/color"(controller: "color", parseRequest: true) { action
- 创造一种颜色
- 根据id获取特定颜色
- 获取所有颜色
"/$controller/$action?/$id?"{
constraints {
// apply constraints here
}
}
"/color"(controller: "color", parseRequest: true) {
action = [GET: "list", POST: "save"]
}
"/color/$id" (resource: "color")
上述方法对于REST和基于浏览器的交互都不起作用
http://localhost:8080/color/create
最终转到显示
操作。我希望它转到显示表单的create
action
如果我删除了最后一个映射“/color/$id”(资源:“color”)
,那么它可以正常工作,但是URLhttp://localhost:8080/color/7
中断
问题
使所有这些URL一致工作的正确方法是什么?为
urlMapping
添加一个约束,并确保默认映射可用
"/$controller/$action?/$id?"{
constraints {
// apply constraints here
}
}
"/user/$id" (resource: "user"){
constraints {
id validator: {
!(it in ['create', 'otherAction'])
}
}
}
顺便提一下,也回答了一个类似的问题