在我的项目中,我使用抽象控制器来包装一些基本的其余内容。
假设我们有一个基域类:
abstract class Entity
。和一个基本控制器:
abstract class CrudController<
Domain extends Entity,
DTO extends Command<Domain>,
Service extends CrudService<Domain>> {
//...//
def insert(DTO dto) {
//..//
}
//...//
}
class Command<Domain extends Entity> {
}
然后我们就有了我们的实现:
SomeController extends CrudController<SomeDomain,SomeCommand,SomeService>
SomeCommand extends Command<SomeDomain>
SomeDomain extends Entity
代码编译时没有任何抱怨,但插入方法总是收到 null。我走在正确的轨道上吗?我怎样才能做到这一点?
更新
看来 insert 方法接收的是
Command
而不是 SomeCommand
实例。
使用超级属性创建显式默认值。它对我有用:
ClassConstructor() {
this.propOne = super.propOne
this.propTwo = super.propTwo
}