-
Notifications
You must be signed in to change notification settings - Fork 38.5k
Allow @PathVariable to have default value on @ModelAttribute methods [SPR-12305] #16910
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Rossen Stoyanchev commented An optional Note that today We can consider some way to allow optional |
Manuel Jordan commented Good to know it can has a solution, but I don't understand your explanation, in your convenience, would you share a simple snippet code (how a draft in a new comment) to understand your idea and see if it resolves my "Addition" and "Second Addition" sections of my shared link? |
Rossen Stoyanchev commented Sure, for example: @ModelAttribute("deportistaActualizar")
public Deportista populateActualizarFormulario(@PathVariable Map<String, String> pathVars){
logger.info("populateActualizarFormulario - pathVars: {}", pathVars);
String id = pathVars.get("id");
return (id != null) ? this.fakeMultipleRepository.findDeportista(id) : null;
} |
Manuel Jordan commented
I don't remember have read an example about that on Spring Reference documentation. Thanks by the snippet code. I understand now. Since it is a Map<String, String> I am assuming it should work for the following scenario: it to represents the URL: deportista/{id}/detalle/something/{abc} Then: @ModelAttribute("deportistaActualizar")
public Deportista populateActualizarFormulario(@PathVariable Map<String, String> pathVars){
logger.info("populateActualizarFormulario - pathVars: {}", pathVars);
String id = pathVars.get("id");
String abc = pathVars.get("abc"); //NEW
return (id != null) ? this.fakeMultipleRepository.findDeportista(id) : null;
} Am I correct? |
Rossen Stoyanchev commented Yes that's correct. It's basically a way to get all path variables in a map. The same pattern is also supported in other places (e.g. |
Manuel Jordan commented Thank you, I have checked the Spring Framework Reference Documentation and there is no an example about Should I create a new issue? |
Rossen Stoyanchev commented Sure, thanks. |
Manuel Jordan commented Sorry by the huge delay, busy a lot. Thank You |
Manuel Jordan opened SPR-12305 and commented
The link shared above is going to be used to ask for many "improvements"
Here the summary of my request: If
@RequestParam
has the option to set a default value, would be viable add the same feature to@PathVariable
?It to work together with
@ModelAttribute
methods, in the same way@RequestParam
does.The reason in the link, see "Addition" and "Second Addition" sections
I want avoid create many
@Controller
'sAffects: 4.0.7
Reference URL: http://stackoverflow.com/questions/25900993/spring-mvc-request-scope-trying-to-update-a-command-object-with-binder-setdisa
Issue Links:
@PathVariable
,@RequestHeader
&@RequestParam
using Map<String, String>The text was updated successfully, but these errors were encountered: