요청 핸들러 메서드의 매개변수로 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가 매칭이 안됐다.

BELATED ARTICLES

more