我将UrlMappings中的页面映射更改为以下值:
name producingCountry: "${adminArea}/producing-country/$id" (controller: "producingCountry", view: "/producingCountry/show") {
constraints { id(matches: /\d+/) }
}
页面(/ productionCountry / 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映射到 Controller 方法“show”(最后一行)时,它运行良好:
render [producingCountry: (country)]
如何解决此问题?
最佳答案
使用此映射
"/${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
关于grails - 将页面映射从 Controller 方法更改为显式 View 页面后,不呈现消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16876824/