Grails 3.3.3生成所有< domain class>仅创建服务接口 [英] Grails 3.3.3 generate-all <domain class> Creates only the Service Interface

查看:37
本文介绍了Grails 3.3.3生成所有< domain class>仅创建服务接口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Grails 3.3.3中,当我为域类运行 generate-all 时,将生成一个服务接口(与Grails 2.x中的实际服务类相对).实际上,直到我尝试向服务中添加方法后,我才注意到它.

In Grails 3.3.3, when I run generate-all for a domain class, a Service Interface is generates (versus the actual Service Class from Grails 2.x). I actually didn't notice it until I tried to add a method to my service.

该界面将放置在该服务所在的服务文件夹中.我实际上确实喜欢该界面,但是我仍然想要该服务和默认实现.如果接口已经具有服务名称,如何在服务文件夹中同时包含接口和实现?(例如,该接口被命名为 ClientService.groovy ,因此该实现将具有相同的名称)

The interface gets placed in the services folder where the service would live. I actually do like the interface but I still want the service and the default implementations. How can I have both an interface and implementation live in the services folder if the interface already has the name of the service? (Ex the interface gets named ClientService.groovy so the implementation would have the same name)

这里是生成接口的示例

package project

import grails.gorm.services.Service

@Service(Client)
interface ClientService {

    Client get(Serializable id)

    List<Client> list(Map args)

    Long count()

    void delete(Serializable id)

    Client save(Client client)

}

推荐答案

如何在其中同时包含接口和实现服务文件夹(如果接口已经具有服务名称)?

How can I have both an interface and implementation live in the services folder if the interface already has the name of the service?

如果您有一个标有 @Service 的接口,那么您根本就不需要任何实现源文件.GORM Data Services会在编译时为您生成实现.如果您想自己编写一些代码,请编写一个抽象类,并使用 @Service 对其进行注释,而不是使用接口.没有理由让您使用标有 @Service 的接口,然后编写实现该接口的类.

If you have an interface marked with @Service then you shouldn't have an implementation source file at all. GORM Data Services generates the implementation for you at compile time. If you want to write some of the code yourself then instead of an interface write an abstract class and annotate it with @Service. There is no reason for you to have an interface marked with @Service and then write a class that implements that interface.

这篇关于Grails 3.3.3生成所有&lt; domain class&gt;仅创建服务接口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆