Grails Command 对象@PostConstruct 还是什么?
我想从注入的服务初始化命令字段。
因此,我需要在命令的方法之后完全初始化,但之前 params
被分配给字段时执行。
我该怎么做呢?好的,我可以在构造函数中手动获取一个 Service bean。还有更好的办法吗?
没有运气 @PostConstruct
或 InitializingBean
- 看起来 Command 不是一个 bean,对吗?
Grails 1.3.5
I want to initialize Command field from an injected Service.
So I need to execute a Command's method after it has been fully initialized, but before params
is assigned to fields.
How can I do it? OK, I can get a Service bean by hand in constructor. Any better way?
Had no luck with @PostConstruct
or InitializingBean
- looks like Command is not a bean, right?
Grails 1.3.5
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你是对的,命令不是 bean。您可以通过服务方法实例化命令实例并在那里进行初始化并将实例返回到控制器。比使用返回的实例调用控制器的bindData,如下所示:
You're right the command is not a bean. You could instantiate the command instance by a service method and do initialization there and return the instance back to the controller. Than call the controller's bindData with the returned instance like this: