【问题标题】:How to implement grails bean如何实现 grails bean
【发布时间】:2013-08-20 16:53:26
【问题描述】:

在我的 grails 应用程序中,有十个域类,在每个域类中都有一个常见的注释字段。它以当前时间戳折衷了当前经过身份验证的用户。

如何使用 bean 实现上述 cmets

【问题讨论】:

  • Inheritance 怎么样?
  • 请尝试更详细地编辑您的问题!

标签: grails javabeans


【解决方案1】:

创建评论域类

class comment 
{
   String message;
   static belongsTo=[User]  //add or can leave it , for all your ten domains

}

然后你需要将它与你的域类的 10 关联起来,ex.User

class User {

    String UserName
    static hasMany=[comments:Comment] // if you have many commentin one pass or
    Comment comment  ///just one to one relationship for every login one record 

     }

还有豆子,

你可以创建一个commentService来操作评论和你的领域类,grails在你创建commentService之后会自动创建一个DI bean 你可以有一些将被注入的示例服务方法

         def registerInfo (){

           //do some comment and domin related stuff
             }

          like in a controller login 

         def commentService 

         def signin(){

          commentService.registerInfo(params)

          }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-03-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-15
    • 1970-01-01
    相关资源
    最近更新 更多