我将UrlMappings中的页面映射更改为以下值:
name producingCountry: "${adminArea}/producing-country/$id" (controller: "producingCountry", view: "/producingCountry/show") {
constraints { id(matches: /\d+/) }
}
页面(/ producingCountry / show)非常简单:
<%@ page contentType="text/html;charset=UTF-8" %>
<html>
<head>
<meta name="layout" content="main">
<title><g:message code="producingCountry.show.title"/></title>
</head>
<body>
</body>
</html>
不再呈现消息。当它的url被映射到控制器方法'show'时,它的工作正常,最后一行如下:
render [producingCountry: (country)]
如何解决此问题?
答案 0 :(得分:0)
使用此映射
"/${adminArea}/producing-country/$id" (controller: "producingCountry", view: "show")
指定controller
时,view
采用名称而不是相对路径。
<强>更新强>
我不确定如何评估adminArea
,但以下内容对我有用:
//UrlMapping:- [mark the "/" in the beginning of the mapping, it is required to append to root context]
name producingCountry: "/admin/producing-country/$id" (controller: "producingCountry", view: "show") {
constraints { id(matches: /\d+/) }
}
//show.gsp
Exactly same (copied) from your question.
//messages.properties
producingCountry.show.title=United States
如果点击了以下网址模式,则会给我一个标题为United States
的网页:
http://localhost:8080/DemoUrlMappingApp/admin/producing-country/123
答案 1 :(得分:0)
我认为在urlMapping定义中指定视图名称时不应指定controller参数,请尝试:
"/${adminArea}/producing-country/$id" (view: "/producingCountry/show")