【发布时间】:2009-12-22 02:38:17
【问题描述】:
我曾经使用"@RequestParam("a-b") String foo" 来接收来自http 查询的"a-b" 参数。
现在我想切换到命令对象,但我不知道如何接收这个参数,我尝试了以下 4 种形式“ab”、“aB”、“a_b”、“a_B”,但都不起作用,例如,下面的代码会变成
网址:http://localhost:8080/test1?a-b=1
结果:Foo{ab='null', aB='null', a_b='null', a_B='null'}
提前致谢
@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 + '\'' +
'}';
}
}
}
【问题讨论】:
标签: spring spring-mvc