본문 바로가기

컴퓨터공학/Spring & Hibernate

Spring> MVC> From Tags and Data Binding

복습용


Text field

submit 버튼을 누르면 스프링은 student.setFirstName( ) / student.setLastName( )을 부른다.


Drop down list

 

form:option 값이 선택되면 student.country 필드 값에 저장하는 기능이다.

submit을 누르면 student.setCountr( ) 이 실행되어서 저장한다. 

 

jsp 에서 student.country 를 하면 student.getCountry( ) 를 실행하여 값을 표현한다. 


Drop box list with items

Key/code 값과 Value/label 으로 구성되어있다.

form이 로드될 때 스프링은 getCountryOptions를 부를 것이다.

 

items는 데이터의 컬렉션을 의미한다. countryOptions는 getCountryCoptions( )를 부른다.

옵션으로써 데이터 목록을 보여주고 겨기서 선택된 값은 student 클래스 country 필드에 저장된다.

그리고 결과 확인 페이지에서 country 값을 보여줄 땐 key값이 보여진다. 

 


Radio box

 

원리는 같다. Radiobox의 문법만 익히자.


Radio box with items

jsp 파일에서 student.countryOptions를 하면 student.getCountryOptions( )를 실행한다.  

submit을 누르면 student.setCountry( ) 실행되어 선택된 값을 student의 country 필드에 넘긴다.

 


Check box 

이전과 원리는 동일하다. checkbox form이 operatingSystems 필드에 저장된다.

submit을 누르면 student.setOperatingSystems( ) 이 실행되어 저장된다. 

 

이전과 다른 점은 배열 필드이다.

 

JSTL 을 부른다. 그리고 배열을 items에다가 저장한 다음 c:forEach로 temp에 저장하여 하나씩 표현한다.