Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring MVC is dropping a @PathVariable

Tags:

spring-mvc

If I hit the controller multiple times and hammer it, occasionally my modelCode parameter comes through as null. However the URL has the modelCode in it. Using Spring Framework 3.0.5.RELEASE

 @RequestMapping(value="ws/getallvariants/{channelCode}/{modelCode}/{regionId}/{year}")
    public ModelAndView getAllVariants(@PathVariable("channelCode") String channelCode, 
          @PathVariable("modelCode") String modelCode,@PathVariable("regionId") String regionId,@PathVariable("year") String year){ 

    if (modelCode == null)
    {
        int i = 0; // this should never hit, but does.
    }

like image 930
Dilbert789 Avatar asked Jun 07 '26 05:06

Dilbert789


2 Answers

Yes, RegEx was the most reliable for me as well. Did this to grab an email address as a parameter:

@RequestMapping(value = "rest/userreadserv/search/{email:.+}", method = RequestMethod.GET)
public ResponseEntity getUserAccountByEmail(@PathVariable String email) {...}
like image 153
Todd Avatar answered Jun 10 '26 17:06

Todd


Take a look at Spring MVC @PathVariable getting truncated . The regex approach worked for me:

@RequestMapping({ "/servers/{serverName:.+}" })

like image 41
Ted Pennings Avatar answered Jun 10 '26 18:06

Ted Pennings



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!