我正在开发一个 Grails 应用程序,其中一些子域类扩展了一个基本抽象域类。我还有一个包含许多抽象域类的父域类。当您为父级运行“grails generate-all”然后创建一个带有一堆子级的父级时,列表视图中的链接指向没有控制器或视图的抽象域类。让这种观点发挥作用的最简单方法是什么?如果问题有点模糊,下面是一些伪代码,以帮助使事情更清楚。
领域类
abstract class Automobile{
String description
}
class Car extends Automobile{}
class Truck extends Automobile{}
class Dealership{
static hasMany = [automobiles:Automobile]
}
用汽车和卡车创建经销商
def car = new Car(description:"Toyota Camry").save()
def truck = new Truck(description : "Toyota Tacoma").save()
def dealership = new Dealership()
dealership.addToAutomobiles(car)
dealership.addToAutomobiles(truck)
dealership.save()
为 Dealership 生成的 show.gsp 将如下所示:
<htm>
<table>
<tr>
<th>Id</th>
<td>${dealershipInstance.id}</td>
</tr>
<tr>
<th>Automobiles</th>
<td>
<ul>
<g:each in="${dealershipInstance.automobiles}" status="i" var="automobileInstance">
<li><g:link action="show" id="${automobileInstance.id}">${automobileInstance.description}</g:link></li>
</g:each>
</ul>
</td>
</tr>
</table>
</html>
问题在于与汽车实例的链接,因为基础抽象类汽车没有自己的视图。因此“显示”操作返回 404。在这种情况下,链接到适当的域类的最佳方式是什么?可能有一个简单的方法来解决这个问题,我只是还没有找到它。
在此先感谢您的帮助。