Java WebDataBinder#getObjectName()能否返回null?

Java WebDataBinder#getObjectName()能否返回null?,java,spring,spring-mvc,data-binding,Java,Spring,Spring Mvc,Data Binding,我延伸 public class RenamingProcessor extends ServletModelAttributeMethodProcessor { @Override protected void bindRequestParameters(WebDataBinder binder, NativeWebRequest nativeWebRequest) { ... binder.get

我延伸

public class RenamingProcessor extends ServletModelAttributeMethodProcessor {
        @Override
        protected void bindRequestParameters(WebDataBinder binder,     NativeWebRequest nativeWebRequest) {
            ...    
            binder.getObjectName();
            ...
        }
}
能否
binder.getObjectName()
返回空值

我试图研究源代码,但在javadoc中找不到这些信息?

不,它不能返回null(在这个语句中,我假设spring框架没有被破坏)

首先,WebDataBinder总是有一个值。查看他们使用的
WebDataBinder活页夹
,如下所示:

ServletRequestDataBinder servletBinder = (ServletRequestDataBinder) binder;
//No null check between cast and usage
servletBinder.bind(servletRequest);
使用哪个构造函数构建您收到的WebDataBinder并不重要。其中2个可从以下网址获得:

第二个很明显将有一个objectName——在这个意义上,我不相信任何在spring上工作的理智的程序员都会用空值调用它

第一个函数调用,该函数使用objectName(public-DataBinder(Object-target,String-objectName))调用构造函数,默认objectName除外:

this(target, DEFAULT_OBJECT_NAME);
那是

public static final String DEFAULT_OBJECT_NAME = "target";
objectName没有设置程序。一旦初始化,它将保持有一个值

旁注:如果绑定器仅用于转换普通参数值,则目标属性(
getTarget()
)可以具有空值。不确定此tho的应用程序



更新:清除。

如果活页夹仅用于转换普通参数值。请澄清这句话?我之所以提到它,是因为我在WebDataBinder父类DataBinder的文档中看到了它,我觉得它很有趣。实际上,我已经看过了,但还没有看到任何这样的用法,而且我自己也很好奇,如果没有其他方法,您会如何使用databinder,可能只有一些方法作为实用工具。不管怎么说,请随便问另一个问题,这会成为一个有趣的问题。实际上我自己也问了一个问题(我跟着你的问题)。事实上,在代码评审中,我被要求检查GetObjectName的NPE结果。这个答案为我澄清了这个问题
public static final String DEFAULT_OBJECT_NAME = "target";