728x90
더보기
Day71. 230808
PathVariable
파라미터를 받을 때 PathVariable로 받아주고
RequestMapping을 /board/{userId}/{grade}/List/{no} 로 해준다면
요청주소가 http://localhost:8081/app/board/hongid/siver/List/1이었을 때
userId=hongid,grade=grade,no=1의 값을 받는다.
요청주소를 http://localhost:8081/app/board/leeid/vip/List/100로 달리 해주면 요청주소에 맞게 값을 받는다.
RequestMapping
클래스 최상단에 RequestMapping을 해준다면 각각의 요청주소 앞에 Mapping한 값이 추가된다.
value값으로 여러 개의 RequestMapping을 해준다면 요청 주소를 한번에 처리해 줄 수도 있다.
session객체를 선언할때와 setAttribute만을 이용해 바로 사용했을 때 같은 결과가 나온다.
addAttribute값에 DTO를 넣는다면 DTO의 값을 가져올 수 있다.
아직 DB연동 전이기에 null값이 들어갔다.
값을 직접 넣어 가져오고 싶다면 DTO에 값을 넣거나 List로 처리해 값을 넣어 줄 수 있다.
여기서 model.addAttribute("am4",testDTO); 와 model.addAttribute(testDTO); 같은 값을 갖는다.
속성명은 model값의 타입으로 사용되는 bean과 동일 할 때는 생략할 수 있다.
728x90
'개발 수업 > Spring' 카테고리의 다른 글
[spring] mybatis 환경 설정 (0) | 2023.08.09 |
---|---|
[spring] model을 전달하는 방법 2가지/ModelAndView ,setViewName (0) | 2023.08.08 |
[spring] 파라미터 값이 null값일 때 처리/파라미터 Map방식,List방식,DTO로 받기 (0) | 2023.08.08 |
[spring] Logging (0) | 2023.08.08 |
[spring] 추가 환경 설정(STS.ini,JavaSE-1.8 설정,org.springframework-version 변경) (0) | 2023.08.08 |