接口 RedirectAttributes
- 所有超级接口:
Model
- 所有已知实现类:
RedirectAttributesModelMap
public interface RedirectAttributes extends Model
A specialization of theModel
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 inorg.springframework.web.servlet.view.RedirectView
.This interface also provides a way to add flash attributes. For a general overview of flash attributes see
FlashMap
. You can useRedirectAttributes
to store flash attributes and they will be automatically propagated to the "output" FlashMap of the current request.Example usage in an
@Controller
:@RequestMapping(value = "/accounts", method = RequestMethod.POST) public String handle(Account account, BindingResult result, RedirectAttributes redirectAttrs) { if (result.hasErrors()) { return "accounts/new"; } // Save account ... redirectAttrs.addAttribute("id", account.getId()).addFlashAttribute("message", "Account created!"); return "redirect:/accounts/{id}"; }
A RedirectAttributes model is empty when the method is called and is never used unless the method returns a redirect view name or a RedirectView.
After the redirect, flash attributes are automatically added to the model of the controller that serves the target URL.
- 从以下版本开始:
- 3.1
- 作者:
- Rossen Stoyanchev
方法概要
所有方法 实例方法 抽象方法 修饰符和类型 方法 说明 RedirectAttributes
addAllAttributes(Collection<?> attributeValues)
Copy all attributes in the suppliedCollection
into thisMap
, using attribute name generation for each element.RedirectAttributes
addAttribute(Object attributeValue)
Add the supplied attribute to thisMap
using agenerated name
.RedirectAttributes
addAttribute(String attributeName, Object attributeValue)
Add the supplied attribute under the supplied name.RedirectAttributes
addFlashAttribute(Object attributeValue)
Add the given flash storage using agenerated name
.RedirectAttributes
addFlashAttribute(String attributeName, Object attributeValue)
Add the given flash attribute.Map<String,?>
getFlashAttributes()
Return the attributes candidate for flash storage or an empty Map.RedirectAttributes
mergeAttributes(Map<String,?> attributes)
Copy all attributes in the suppliedMap
into thisMap
, with existing objects of the same name taking precedence (i.e. not getting replaced).从接口继承的方法 org.springframework.ui.Model
addAllAttributes, asMap, containsAttribute
方法详细资料
addAttribute
RedirectAttributes addAttribute(String attributeName, Object attributeValue)
从接口复制的说明:Model
Add the supplied attribute under the supplied name.- 指定者:
addAttribute
在接口中Model
- 参数:
attributeName
- the name of the model attribute (nevernull
)attributeValue
- the model attribute value (can benull
)
addAttribute
RedirectAttributes addAttribute(Object attributeValue)
从接口复制的说明:Model
Add the supplied attribute to thisMap
using agenerated name
.Note: Empty Collections
are not added to the model when using this method because we cannot correctly determine the true convention name. View code should check fornull
rather than for empty collections as is already done by JSTL tags.- 指定者:
addAttribute
在接口中Model
- 参数:
attributeValue
- the model attribute value (nevernull
)
addAllAttributes
RedirectAttributes addAllAttributes(Collection<?> attributeValues)
从接口复制的说明:Model
Copy all attributes in the suppliedCollection
into thisMap
, using attribute name generation for each element.- 指定者:
addAllAttributes
在接口中Model
- 另请参阅:
Model.addAttribute(Object)
mergeAttributes
RedirectAttributes mergeAttributes(Map<String,?> attributes)
从接口复制的说明:Model
Copy all attributes in the suppliedMap
into thisMap
, with existing objects of the same name taking precedence (i.e. not getting replaced).- 指定者:
mergeAttributes
在接口中Model
addFlashAttribute
RedirectAttributes addFlashAttribute(String attributeName, Object attributeValue)
Add the given flash attribute.- 参数:
attributeName
- the attribute name; nevernull
attributeValue
- the attribute value; may benull
addFlashAttribute
RedirectAttributes addFlashAttribute(Object attributeValue)
Add the given flash storage using agenerated name
.- 参数:
attributeValue
- the flash attribute value; nevernull
getFlashAttributes
Map<String,?> getFlashAttributes()
Return the attributes candidate for flash storage or an empty Map.