@ModelAttribute
request 파라미터와 1:1 매핑해서 변수에 받으려면 @RequestParam을 사용하고
DTO같은 객체에 여러 파라미터를 한번에 바인딩 하려면 @ModelAttribute를 사용하면 된다.
URL 입력 예) /methodparam/m12?seq=100&id=kdarkdev&level=4&country=kr
1. DTO클래스
01.public class UserDTO {02.private long seq;03.private String id;04.private int level;05.private String country;06.public long getSeq() {07.return seq;08.}09.public void setSeq(long seq) {10.this.seq = seq;11.}12.public String getId() {13.return id;14.}15.public void setId(String id) {16.this.id = id;17.}18.public int getLevel() {19.return level;20.}21.public void setLevel(int level) {22.this.level = level;23.}24.public String getCountry() {25.return country;26.}27.public void setCountry(String country) {28.this.country = country;29.}30.@Override31.public String toString() {32.return "UserDTO [seq=" + seq + ", id=" + id + ", level=" + level33.+ ", country=" + country + "]";34.}35.}1.@RequestMapping("/methodparam/m12")2.public String m12(@ModelAttribute UserDTO dto){3.System.out.println(dto);4.return "test";5.}'Back-End > Spring' 카테고리의 다른 글
| Spring에서 SQL Exception 처리하기. (0) | 2014.03.05 |
|---|---|
| @RequestParam - 1:1로 파라미터 집어넣기 (0) | 2012.09.11 |
| 스프링에서 Quartz 를 사용하여 잡스케줄링 하기 [출처] [본문스크랩] 스프링에서 Quartz 를 사용하여 잡스케줄링 하기|작성자 onandme (0) | 2012.08.17 |
| 기술에 독립적인 DAO를 만들기 위한 DataAccessException (0) | 2012.07.23 |
| SpringMVC에서 간단한 ExceptionResolver 구성하기 (0) | 2012.06.26 |