parameter값으로 객체 property 채우기
2018. 7. 18. 17:19
요청 핸들러 메서드의 매개변수로 Board board 처럼 객체를 선언하면 frontController가 xml 설정 파일을 읽어서 iocContainer에 객체를 생성해놓을 때 Board 객체를 생성해놓는다.
그리고 parameter 값과 board 객체의 property가 일치하는 값이 있으면 자동 매칭돼서 객체에 입력된다.
@GetMapping(value="m1")
@ResponseBody
public String m1(Board board) {
return String.format("m1(): no=%d, title=%s, content=%s",
board.getNo(),
board.getTitle(),
board.getContent());
}
리턴 값으로 No, Title, Content를 받아서 반환했고 Board 객체에는 해당 property들이 존재하고 있다.
int no;
String title;
String content;
Date createdDate;
Member user;
만약 property와 parameter가 서로 매칭이 안되면 객체에는 아무것도 들어가지 않기에 Null값이 출력된다.
결과 / m1(): no=11, title=aaaa, content=null
// content가 매칭이 안됐다.
'Spring' 카테고리의 다른 글
파라미터 값으로 Date 타입 받기 (0) | 2018.07.18 |
---|---|
Spring 실행 방법 톰캣 서버 실행 (0) | 2018.05.04 |
Spring 프로젝트 불러오기, 내보내기 (Import, Export) (0) | 2018.05.03 |
스프링 톰캣 연동 (0) | 2018.05.03 |
스프링(STS) 다운로드 (0) | 2018.05.01 |