대충벌레 블로그
Published 2021. 1. 29. 18:00
스프링 공부 IT 기술/스프링[Spring]
728x90
반응형
<java />
package config; import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer; import org.springframework.web.servlet.config.annotation.EnableWebMvc; import org.springframework.web.servlet.config.annotation.ViewResolverRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; @Configuration @EnableWebMvc public class MvcConfig implements WebMvcConfigurer { @Override public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) { configurer.enable(); } @Override public void configureViewResolvers(ViewResolverRegistry registry) { registry.jsp("/WEB-INF/view/", ".jsp"); } }

registry.jsp() 코드는 JSP 를 뷰 구현으로 사용할 수 있도록 해주는 설정 

<java />
import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestParam; @Controller public class HelloController { @GetMapping("/hello") public String hello(Model model, @RequestParam(value = "name", required = false) String name) { model.addAttribute("greeting", "안녕하세요, " + name); return "hello"; } }

컨트롤러에서 설정한 속성을 JSP뷰에서 접근할수 있는 이유는

스프링MVC 프레임워크가 HttpServletRequest에 옮겨주기 때문

 

 

반응형
profile

대충벌레 블로그

@대충벌레

포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!