Grails 3.3.3 generate-all <domain class> 仅创建服务接口
Grails 3.3.3 generate-all <domain class> Creates only the Service Interface
在 Grails 3.3.3 中,当我 运行 generate-all
用于域 class 时,会生成一个服务接口(相对于来自 Grails 的实际服务 Class 2.x).我实际上并没有注意到它,直到我尝试向我的服务添加一个方法。
界面被放置在服务所在的服务文件夹中。我确实喜欢这个界面,但我仍然想要服务和默认实现。如果接口已经具有服务名称,我如何才能让接口和实现同时存在于服务文件夹中? (例如,接口被命名为 ClientService.groovy
,因此实现将具有相同的名称)
这是生成的接口示例
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 数据服务在编译时为您生成实现。如果你想自己写一些代码,那么写一个抽象的 class 而不是接口,然后用 @Service
注释它。您没有理由拥有一个标有 @Service
的接口,然后编写一个 class 来实现该接口。
在 Grails 3.3.3 中,当我 运行 generate-all
用于域 class 时,会生成一个服务接口(相对于来自 Grails 的实际服务 Class 2.x).我实际上并没有注意到它,直到我尝试向我的服务添加一个方法。
界面被放置在服务所在的服务文件夹中。我确实喜欢这个界面,但我仍然想要服务和默认实现。如果接口已经具有服务名称,我如何才能让接口和实现同时存在于服务文件夹中? (例如,接口被命名为 ClientService.groovy
,因此实现将具有相同的名称)
这是生成的接口示例
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 数据服务在编译时为您生成实现。如果你想自己写一些代码,那么写一个抽象的 class 而不是接口,然后用 @Service
注释它。您没有理由拥有一个标有 @Service
的接口,然后编写一个 class 来实现该接口。