Negative parameters in the Spring RequestMapping controller

Hello,

I have two methods in my controller, and I try to run one of the methods if the parameter is a specific value, and the other if the parameter is not this value. My "not" method runs when the parameter is equal to a specific value.

According to (my understanding) this I am writing the expression correctly. Here are the signatures of the two methods:

@RequestMapping(value = "/doit", params= {"output=grouped", "display!=1"}) public @ResponseBody HashMap<String, Object> doSomething( @RequestParam("text") String text, @RequestParam("display") String display) { // this method runs if display=1 but why? } @RequestMapping(value = "/doit", params= {"output=grouped", "display=1"}) public @ResponseBody HashMap<String, Object> doSomethingElse( @RequestParam("text") String text) { // this method is not being called when display=1...why not? } 

I have Spring debug logging enabled, and I see where Spring converts the parameter to the RequestParam string with a value of '1'. However, in the very next line, he decides to match it with the wrong method.

What am I doing wrong?

Thanks!

+4
source share
1 answer

This is not your fault: it is a bug SPR-8059 . It is currently fixed in version 3.1M2 and svn Trunk rev 4408 .

A workaround would be to not use != In @RequestMapping . Instead, you should do this with if manually:

 @RequestMapping(value = "/doit", params= {"output=grouped") public @ResponseBody HashMap<String, Object> acceptAll( @RequestParam("text") String text, @RequestParam("display") String display) { if("1".equals(display) { return doSomethingElse(text); } else { return doSomething(text,display); } } 
+3
source

All Articles