【问题标题】:How to insert data to four tables from one view in Grails?如何从 Grails 中的一个视图向四个表中插入数据?
【发布时间】:2012-05-08 02:26:04
【问题描述】:

我在基于 Grails 的 Web 应用程序中有四个域类(我做过的第一个):

class Receipt
{
    String title
    Date dateCreated
    static hasMany = [articles: Article]
    static constraints =
    {
        title blank: false, unique: true
    }
}

class Article
{
    String name
    Quantity quantity
    TypeOfArticle typeOfArticle
    static hasOne = [quantity:Quantity, typeOfArticle:TypeOfArticle]
    static constraints =
    {
        quantity unique: true
    }
}

class Quantity
{
    Integer quantity
    Article article
}

class TypeOfArticle
{
    String type
    Article article
}

如何在一个视图中添加一张收据以及所有详细信息?
我想让它看起来像这张照片: http://i.stack.imgur.com/uNVzW.png

我希望你能帮助我!提前谢谢!

【问题讨论】:

标签: grails grails-orm gsp


【解决方案1】:

您可能想查找命令对象。看起来您正试图让某人将数据输入到一种跨越多个类的表单中。您可以创建一个包含所有四个类的字段的命令对象。您将该对象用于 gsp 字段,然后在控制器方法中捕获并验证数据;然后创建您的实际收据、文章等。

【讨论】:

    【解决方案2】:

    您可以在控制器操作中获取参数,在操作中您可以简单地编写 object.propertyName=params.propertyName 并在获取所有参数后通过调用 object.save 简单地存储它()。您可以对所有四个表执行相同的过程..

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-10-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-23
      • 2017-09-12
      • 2021-05-14
      • 2014-02-17
      相关资源
      最近更新 更多