类 RedirectModel
- 所有已实现的接口:
cn.taketoday.ui.Model,Serializable,Cloneable,Comparable<RedirectModel>,Map<String,Object>
public class RedirectModel
extends cn.taketoday.ui.ModelMap
implements Serializable, Comparable<RedirectModel>
A specialization of the
Model interface that controllers can use to
select attributes for a redirect scenario. Since the intent of adding
redirect attributes is very explicit -- i.e. to be used for a redirect URL,
attribute values may be formatted as Strings and stored that way to make
them eligible to be appended to the query string or expanded as URI
variables in cn.taketoday.web.view.RedirectView.
Example usage in an @Controller:
@RequestMapping(value = "/accounts", method = HttpMethod.POST)
public String handle(Account account, BindingResult result, RedirectModel redirectAttrs) {
if (result.hasErrors()) {
return "accounts/new";
}
// Save account ...
redirectAttrs.addAttribute("id", account.getId());
redirectAttrs.addAttribute("message", "Account created!");
return "redirect:/accounts/{id}";
}
- 从以下版本开始:
- 2.3.3 2018-11-18 16:39
- 作者:
- Harry Yang
- 另请参阅:
-
嵌套类概要
从类继承的嵌套类/接口 java.util.AbstractMap
AbstractMap.SimpleEntry<K extends Object,V extends Object>, AbstractMap.SimpleImmutableEntry<K extends Object, V extends Object> -
字段概要
字段修饰符和类型字段说明private longstatic final StringName of request attribute that holds a RedirectModel with "input" redirect attributes saved by a previous request, if any.static final StringName of request attribute that holds the "output"RedirectModelwith attributes to save for a subsequent request.private static final longprivate String -
构造器概要
构造器构造器说明Construct a new, empty RedirectModel.RedirectModel(String attributeName, Object attributeValue) Construct a newModelMapcontaining the supplied attribute under the supplied name. -
方法概要
修饰符和类型方法说明voidaddTargetRequestParam(String name, String value) Provide a request parameter identifying the request for this RedirectModel.voidaddTargetRequestParams(cn.taketoday.util.MultiValueMap<String, String> params) Provide request parameters identifying the request for this RedirectModel.intcompareTo(RedirectModel other) Compare two RedirectModels and prefer the one that specifies a target URL path or has more target URL parameters.booleanstatic RedirectModelfindOutputModel(cn.taketoday.core.AttributeAccessor attributeAccessor) Return "output" RedirectModel to save attributes for request after redirect.longReturn the expiration time for the RedirectModel or -1 if the expiration period has not started.Return the parameters identifying the target request, or an empty map.Return the target URL path (ornullif none specified).inthashCode()booleanReturn whether this instance has expired depending on the amount of elapsed time since the call tostartExpirationPeriod(int).voidsetExpirationTime(long expirationTime) Set the expiration time for the RedirectModel.voidsetTargetRequestPath(String path) Provide a URL path to help identify the target request for this RedirectModel.voidstartExpirationPeriod(int timeToLive) Start the expiration period for this instance.toString()从类继承的方法 cn.taketoday.ui.ModelMap
addAllAttributes, addAllAttributes, addAttribute, addAttribute, asMap, attributeNames, containsAttribute, getAttribute, mergeAttributes, removeAttribute, setAttribute从类继承的方法 java.util.LinkedHashMap
clear, containsValue, entrySet, forEach, get, getOrDefault, keySet, removeEldestEntry, replaceAll, values从类继承的方法 java.util.HashMap
clone, compute, computeIfAbsent, computeIfPresent, containsKey, isEmpty, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, size从接口继承的方法 java.util.Map
compute, computeIfAbsent, computeIfPresent, containsKey, isEmpty, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, size从接口继承的方法 cn.taketoday.ui.Model
clear, getAttributeNames, isEmpty, setAttributes
-
字段详细资料
-
serialVersionUID
private static final long serialVersionUID- 另请参阅:
-
INPUT_ATTRIBUTE
Name of request attribute that holds a RedirectModel with "input" redirect attributes saved by a previous request, if any. -
OUTPUT_ATTRIBUTE
Name of request attribute that holds the "output"RedirectModelwith attributes to save for a subsequent request. -
targetRequestPath
-
targetRequestParams
-
expirationTime
private long expirationTime
-
-
构造器详细资料
-
RedirectModel
public RedirectModel()Construct a new, empty RedirectModel. -
RedirectModel
Construct a newModelMapcontaining the supplied attribute under the supplied name.- 另请参阅:
-
ModelMap.setAttribute(String, Object)
-
-
方法详细资料
-
setTargetRequestPath
Provide a URL path to help identify the target request for this RedirectModel.The path may be absolute (e.g. "/application/resource") or relative to the current request (e.g. "../resource").
- 从以下版本开始:
- 4.0
-
getTargetRequestPath
Return the target URL path (ornullif none specified).- 从以下版本开始:
- 4.0
-
addTargetRequestParams
Provide request parameters identifying the request for this RedirectModel.- 参数:
params- a Map with the names and values of expected parameters- 从以下版本开始:
- 4.0
-
addTargetRequestParam
Provide a request parameter identifying the request for this RedirectModel.- 参数:
name- the expected parameter name (skipped if empty)value- the expected value (skipped if empty)- 从以下版本开始:
- 4.0
-
getTargetRequestParams
Return the parameters identifying the target request, or an empty map.- 从以下版本开始:
- 4.0
-
startExpirationPeriod
public void startExpirationPeriod(int timeToLive) Start the expiration period for this instance.- 参数:
timeToLive- the number of seconds before expiration- 从以下版本开始:
- 4.0
-
setExpirationTime
public void setExpirationTime(long expirationTime) Set the expiration time for the RedirectModel. This is provided for serialization purposes but can also be used insteadstartExpirationPeriod(int).- 从以下版本开始:
- 4.0
-
getExpirationTime
public long getExpirationTime()Return the expiration time for the RedirectModel or -1 if the expiration period has not started.- 从以下版本开始:
- 4.0
-
isExpired
public boolean isExpired()Return whether this instance has expired depending on the amount of elapsed time since the call tostartExpirationPeriod(int).- 从以下版本开始:
- 4.0
-
compareTo
Compare two RedirectModels and prefer the one that specifies a target URL path or has more target URL parameters. Before comparing RedirectModel instances ensure that they match a given request.- 指定者:
compareTo在接口中Comparable<RedirectModel>
-
equals
-
hashCode
public int hashCode() -
toString
- 覆盖:
toString在类中AbstractMap<String,Object>
-
findOutputModel
@Nullable @Experimental public static RedirectModel findOutputModel(cn.taketoday.core.AttributeAccessor attributeAccessor) Return "output" RedirectModel to save attributes for request after redirect.- 参数:
attributeAccessor- attributeAccessor to use for saving attributes- 返回:
- a
RedirectModelinstance
-