我有一个关于方法getInteger()和getRequiredInteger()之间的区别的快速问题。
public void foo(RequestContext requestContext){
MutableAttributeMap flowScope = requestContext.getFlowScope();
String bar = flowScope.getString("bar","bar"); // (attributeName, defaultValue)
String baz = flowScope.getRequiredString("baz");
}唯一的区别是,使用getInteger(),如果在映射中找不到属性名称,您可以定义一个默认值?
发布于 2013-01-08 03:24:01
根据Spring Web Flow API,两者之间的差异与异常抛出有关-
getRequiredInteger() -返回映射中的整型属性值,如果该属性不存在且类型不正确,则会引发异常。
getInteger() -返回映射中的整型属性值,如果未找到值,则返回默认值。
发布于 2013-01-08 03:20:50
不,主要区别在于,如果属性名称不在映射中,getRequiredInteger将抛出异常。
https://stackoverflow.com/questions/14202555
复制相似问题