문제

In my application I have to compare 3 products for that in my controller I mapped request as

@RequestMapping(value = "/products/{proId1}Vs{proId2}Vs{proId3}", method = RequestMethod.GET)
public ModelAndView compareThreeProducts(@PathVariable("proId1") int id1, @PathVariable("proId2") int id2, @PathVariable("proId3") int id3)
{
   //someLogic

when hit my url(http://something/products/12Vs13Vs14)

I'm getting http 400 error

I also tried for 2 @pathVariable like

@RequestMapping(value = "/products/{proId1}Vs{proId2}", method = RequestMethod.GET)
public ModelAndView compareTwoProducts(@PathVariable("proId1") int id1, @PathVariable("proId2") int id2) 

this is working fine but why i'm facing problem with 3 variables and also there are no errors in server log then how to find what's the bug.

any solution??

도움이 되었습니까?

해결책

You could try lumping everything into one path variable then parsing it manually:

@RequestMapping(value = "/products/{compareIdString}", method = RequestMethod.GET)
public ModelAndView compareThreeProducts(@PathVariable("compareIdString") String compareIdString)
{
    // split compareIdString on "Vs"
    // parse each resulting value to an int

This is more of a workaround than a solution, though. You might want to debug in the Spring code as Bozho suggested if you want to try to figure out exactly what's going wrong.

다른 팁

How about explicitly specifying the regex you want each path variable to match, as described here?

@RequestMapping(value = "/products/{proId1:\d+}Vs{proId2:\d+}Vs{proId3:\d+}", method = RequestMethod.GET)

  • make sure the problem is not in the response - put a breakpoint in the method and see if it is invoked
  • check log files for any indications
  • try using slashes as separator /products/{p1}/{p2}/{p3} or /products/{p1}/vs/{p2}/vs/{p3}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top