http 쿼리에서 "a-b"매개 변수를 받기 위해 "@RequestParam ("a-b ") String foo"를 사용했습니다."a-b"쿼리를 Spring MVC의 커맨드 객체에 매핑하는 방법
이제 Command Object로 전환하고 싶지만이 param을받는 방법을 모르겠습니다. "ab", "aB", "a_b", "a_B"의 4 가지 형식을 시도했지만 둘 다 작동하지 않습니다. 예를 들어, 다음 코드가 발생합니다
로 URL : http://localhost:8080/test1?a-b=1결과 :
@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 + '\'' +
'}';
}
}
}
ab는 오래된 API에서 비롯되었으며이 API를 계속 지원해야합니다. 그래서 'ab' 'aB'. 감사합니다. – lidaobing
당신은 이것을 알아 내고, 같은 질문을 여기에 가지고 있습니다. http://stackoverflow.com/questions/20670456/map-post-parameter-with-dash-to-model-in-spring-controller –