我正在尝试将旧的Java项目设置并重新设计为grails。我使用GGTS 3.1.0。我已经配置了我的域模型。我的问题是,当我使用自动生成控制器和视图(右键单击project-> new->生成控制器和视图)时,它会生成文件,但属性并非全部包含在内!我认为这个脚手架将提供一个包含我的域类的所有属性的视图。我错了吗?
副班:
package com.trading.core
class Associate {
Integer id
String name
String address
Prefecture prefecture
SubPrefecture subPrefecture
Municipal municipal
String city
BigDecimal minDiscount
String zipcode
User insUser
Date insDatetime
User updtUser
Date updtDatetime
static mapping = {
table "associate"
id generator: 'identity'
minDiscount column:"min_discount"
insUser column: "ins_user"
insDatetime column: "ins_datetime"
updtUser column: "updt_user"
updtDatetime column: "updt_datetime"
municipal column: "municipal"
subPrefecture column: "sub_prefecture"
prefecture column: "prefecture"
version false
}
static constraints = {
}
}
list.gsp(生成)
<%@ page import="com.trading.core.Associate" %>
<!DOCTYPE html>
<html>
<head>
<meta name="layout" content="main">
<g:set var="entityName" value="${message(code: 'associate.label', default: 'Associate')}" />
<title><g:message code="default.list.label" args="[entityName]" /></title>
</head>
<body>
<a href="#list-associate" class="skip" tabindex="-1"><g:message code="default.link.skip.label" default="Skip to content…"/></a>
<div class="nav" role="navigation">
<ul>
<li><a class="home" href="${createLink(uri: '/')}"><g:message code="default.home.label"/></a></li>
<li><g:link class="create" action="create"><g:message code="default.new.label" args="[entityName]" /></g:link></li>
</ul>
</div>
<div id="list-associate" class="content scaffold-list" role="main">
<h1><g:message code="default.list.label" args="[entityName]" /></h1>
<g:if test="${flash.message}">
<div class="message" role="status">${flash.message}</div>
</g:if>
<table>
<thead>
<tr>
<g:sortableColumn property="name" title="${message(code: 'associate.name.label', default: 'Name')}" />
<g:sortableColumn property="address" title="${message(code: 'associate.address.label', default: 'Address')}" />
<g:sortableColumn property="city" title="${message(code: 'associate.city.label', default: 'City')}" />
<g:sortableColumn property="insDatetime" title="${message(code: 'associate.insDatetime.label', default: 'Ins Datetime')}" />
<th><g:message code="associate.insUser.label" default="Ins User" /></th>
<g:sortableColumn property="minDiscount" title="${message(code: 'associate.minDiscount.label', default: 'Min Discount')}" />
<th><g:message code="associate.municipal.label" default="Municipal" /></th>
</tr>
</thead>
<tbody>
<g:each in="${associateInstanceList}" status="i" var="associateInstance">
<tr class="${(i % 2) == 0 ? 'even' : 'odd'}">
<td><g:link action="show" id="${associateInstance.id}">${fieldValue(bean: associateInstance, field: "address")}</g:link></td>
<td>${fieldValue(bean: associateInstance, field: "city")}</td>
<td><g:formatDate date="${associateInstance.insDatetime}" /></td>
<td>${fieldValue(bean: associateInstance, field: "insUser")}</td>
<td>${fieldValue(bean: associateInstance, field: "minDiscount")}</td>
<td>${fieldValue(bean: associateInstance, field: "municipal")}</td>
</tr>
</g:each>
</tbody>
</table>
<div class="pagination">
<g:paginate total="${associateInstanceTotal}" />
</div>
</div>
</body>
</html>
答案 0 :(得分:2)
脚手架默认只显示一些属性 - 我认为是6.要更改此命令,请执行命令
grails install-templates
然后查看src/templates/scaffolding
,您会看到list.gsp
您可以编辑该文件并删除或修改视图的生成方式(在此问题的代码中查找i < 6
)。然后,下次生成视图时,将使用模板并显示您设置的任意数量的属性。