Hello,
I used to use "@RequestParam("a-b") String foo" to receive the "a-b" parameter from http query.
now I want to switch to Command Object, but I don't how to receive this param, I tried following 4 forms "ab", "aB", "a_b", "a_B", but neither works, for example, the following code will result as
URL: http://localhost:8080/test1?a-b=1
Result: Foo{ab='null', aB='null', a_b='null', a_B='null'}
Thanks in advance
@Controller
public class TestController {
@RequestMapping("/test1")
public String test1(
Foo foo,
HttpServletResponse response
) throws IOException {
response.setContentType("text/plain");
response.getOutputStream().write(foo.toString().getBytes("UTF-8"));
return null;
}
public static class Foo {
private String ab;
private String aB;
private String a_b;
private String a_B;
// getter and setter
...
@Override
public String toString() {
return "Foo{" +
"ab='" + ab + '\'' +
", aB='" + aB + '\'' +
", a_b='" + a_b + '\'' +
", a_B='" + a_B + '\'' +
'}';
}
}
}