@pathvariable

배고픈 징징이 ㅣ 2023. 1. 26. 15:01

@pathvariable

  • URL에 파라미터를 넣고 싶을때 사용한다.​
  • @RequestMapping 어노테이션 값으로 템플릿변수( { } ) 를 사용
  • @PathVariable 어노테이션을 이용해서 템플릿변수( { } ) 와 동일한 이름을 갖는 파라미터를 추가

 

주의사항

  1. . 이 들어가는 값에는 사용하지 않는다. => . 부터 뒤로는 잘려서 넘어온다.
  2. 공백이 들어가는 값에는 사용하지 않는다.
  3. 빈값에는 사용하지 않는다.

 

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/{site}/main")
public class ShelterMainController {	
	@RequestMapping("/login")
	public String login(@PathVariable(value="site") String site) {		
		return "/main/login";
	}
}
반응형

'Java' 카테고리의 다른 글

ThreadLocal  (0) 2023.02.07
Stream  (0) 2023.01.31
VO 데이터 추출  (0) 2023.01.26
Ehcache3 & SpEL  (0) 2023.01.26
Reflection  (0) 2023.01.20