How to access Grails domain classes in Java service layer?

后端 未结 3 1373
难免孤独
难免孤独 2021-01-07 00:46

How can I use grails domain classes (which is in groovy) in service layer which is in Java/Spring.

When using the grails MVC, everything is fine as I can use contro

3条回答
  •  轮回少年
    2021-01-07 00:55

    Where as InvokerHelper works well, if you have access to the GORM class I would put wrapper functions around the GORM calls -- then the Java classes will see that.

    static String List getAll() { return User.list() }
    static String User getByID(long id) { return User.get(id) }
    

    That seems cleaner and doesn't put a dependency on a Groovy class in your Java code.

提交回复
热议问题