목록Server application/Spring (10)
ecsimsw

1. Static Resource 사용하기스프링 부트에서는 /resources/static의 파일을 url 요청으로 접근할 수 있다. resources/static/file/hello.html을 접근한다면 /localhost:8080/file/hello.html 기본 리소스 맵핑은 "/**"이지만, spring.mvc.static-path-pattern을 설정해서, url에 접근 경로를 지정할 수 있다. static path pattern은 application.yml에서 설정한다. spring.mvc.static-path-pattern: /static/** 위의 예시처럼 /static/**으로 설정한다면, 이후로는 정적 리소를 localhost:port/static/ 아래에서 접근하는 것이다. res..
RedirectAttributes 의 addAttribute RedirectAttributes.addAttribute을 이용하는 경우 쿼리 파라미터로 데이터가 포함되어 재요청된다. 예를 들어 아래처럼 핸들러를 작성하는 경우 리다이렉트의 요청 url은 '/redirected?name=jinhwan' 일 것이다. @GetMapping(value="/hello") public String hello(RedirectAttributes redirectAttributes){ redirectAttributes.addAttribute("name", "jinhwan"); return "redirect:/redirected"; } 이는 리다이렉트 시 넘겨야하는 값이 쿼리에 표시가 되어야하기 때문에 String으로 변환이 ..