Spring @RequestParam does not handle multiple variables correctly - test case example

The test case below shows a simple case when I have 2 parameters paramAand paramB.

  • If I call /paramtesturl, the method is called paramtest().
  • If I enter truefor paramA, the method is called aTrue().
  • However, when entering truefor paramAand paramB, the method is called bTrueNotA().

But the third @RequestMappingcauses A=Trueand B!=true. On my repeated termination, when both parameters are correct, it should be called aTrue().

@RequestMapping("paramtest")
@ResponseBody
public String paramtest(){
    return  "<html><head></head><body>" +
                "<form action=paramtest method=post>" +
                    "paramA: <input type=text name=paramA /><br>" +
                    "paramB: <input type=text name=paramB /><br>" +
                    "<input type=submit>" + 
                "</form>" +
            "</body></html>";       
}

@RequestMapping(value="paramtest", params="paramA=true")
@ResponseBody
public String aTrue(){
    return "A=true";
}

@RequestMapping(value="paramtest", params={"paramB=true", "paramA!=true"})
@ResponseBody
public String bTrueNotA(){
    return "B=True; A!=true";
}
+3
source share
1 answer

I think this might be a bug in Spring. I tried with the following mappings:

@RequestMapping(value="/paramtest", params={"paramA=true"})
@ResponseBody
public String function A() { return "A"; }

@RequestMapping(value="/paramtest", params={"paramA=true", "paramB=foobar"})
@ResponseBody
public String function B() { return "B"; }

@RequestMapping(value="/paramtest", params={"paramA=!true", "paramB=foo"})
@ResponseBody
public String function C() { return "C"; }

, , :

paramA=true A()

paramA=true, paramB=foobar B()

paramA=not_true, paramB=foo 404 , C(), .

Tomcat:

WARN org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver 142 - No matching handler method found for servlet request: path '/paramtest', method 'POST', parameters map['paramB' -> array<String>['foo'], 'paramA' -> array<String>['not_true']]

Spring 3.0.5. , myParam!=myValue Spring 3.0.4 (3.0.3 doc ). , , !myParam=myValue , 3.0.5.

, , :)

+1

All Articles