Skip to content

Use AbstractView instead of HandlerMethodArgumentResolver to add @PathVariable values to the model [SPR-8484] #13130

@spring-projects-issues

Description

@spring-projects-issues

Rossen Stoyanchev opened SPR-8484 and commented

As part of #12200, milestone 2 of Spring 3.1, support was added to automatically expose @PathVariable values in the model. This is quite useful in cases where a view prepares links to related URLs (#11152). However, it can get in the way in cases where the model is used in an automated way such as when model attributes are appended to a redirect URL (#13094), or when views generate the response from the model - MarshallingView, MappingJacksonJsonView.

Rather than adding path variables to the model prior to invoking the controller method (like @ModelAttribute), path variables can be added via AbstractView.render(..), which already deals with adding static attributes and a RequestContext. This has several advantages:

  • The feature applies only to methods not annotated with @ResponseBody
  • View types can decide individually (e.g. turned off by default for MarshallingView and MappingJacksonJsonView)
  • Applications can override the default settings via AbstractView and UrlBasedViewResolver

Affects: 3.1 M2

Issue Links:

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: taskA general task

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions