[英]Understanding legacy grails code?
The following is a chunk of code in setUp method of controller unit test class in grails. 以下是grails中控制器单元测试类的setUp方法中的代码块。 I am trying to understand the purpose of the following setup code. 我试图了解以下安装代码的目的。 The application has a TimeService which is responsible for doing time operations. 该应用程序具有一个TimeService,它负责执行时间操作。 I appreciate any help! 感谢您的帮助!
def customPropertyEditor = new CustomPropertyEditorRegistrar(timeService: new TimeService())
def map = (Map<String, PropertyEditorRegistrar>) servletContext.getAttribute(GrailsDataBinder.PROPERTY_EDITOR_REGISTRARS)
if (!map) servletContext.setAttribute(GrailsDataBinder.PROPERTY_EDITOR_REGISTRARS, [customPropertyEditor: customPropertyEditor])
else map.put('customPropertyEditor', customPropertyEditor)
Create this TimeService object that is customPropertyEditor
创建此customPropertyEditor
对象为customPropertyEditor
def customPropertyEditor = new CustomPropertyEditorRegistrar(timeService: new TimeService())
Make a map out of servletContext.getAttribute(GrailsDataBinder.PROPERTY_EDITOR_REGISTRARS
使用servletContext.getAttribute(GrailsDataBinder.PROPERTY_EDITOR_REGISTRARS
def map = (Map<String, PropertyEditorRegistrar>) servletContext.getAttribute(GrailsDataBinder.PROPERTY_EDITOR_REGISTRARS)
if (!map)
= If no map found = as in null due to no results if (!map)
=如果未找到地图=由于没有结果,为null
Then set servletContext.setAttribute(GrailsDataBinder.PROPERTY_EDITOR_REGISTRARS
to be the object at the top customPropertyEditor
然后将servletContext.setAttribute(GrailsDataBinder.PROPERTY_EDITOR_REGISTRARS
设置为顶部customPropertyEditor
的对象
servletContext.setAttribute(GrailsDataBinder.PROPERTY_EDITOR_REGISTRARS, [customPropertyEditor: customPropertyEditor])
If there was a map put in the map customPropertyEditor this value 如果在地图customPropertyEditor中放置了地图,则此值
else map.put('customPropertyEditor', customPropertyEditor)
As for what GrailsDataBinder
is doing as Servlet
Attribute
have a search for it in the code base to see what other things are interacting 至于GrailsDataBinder
作为Servlet
Attribute
所做的事情,请在代码库中进行搜索,以查看其他哪些内容正在交互
ok i found that this chunk of code is responsible for making it so that date binds well. 好的,我发现这段代码负责完成此工作,以便日期绑定良好。 Apparently, there is no clean method to bind date in grails 2.2. 显然,grails 2.2中没有绑定日期的干净方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.