728x90
반응형
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 를 뷰 구현으로 사용할 수 있도록 해주는 설정
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에 옮겨주기 때문
반응형
'IT 기술 > 스프링[Spring]' 카테고리의 다른 글
[Spring Security] Spring boot 3 이상 버전 OAuth2 오류 (1) | 2024.02.07 |
---|---|
SqlMapClientFactoryBean , SqlSessionFactoryBean (0) | 2021.01.05 |
JdbcTemplate , SqlMapClientDaoSupport (0) | 2021.01.04 |
Unable to find setter method for attribute :[commandName] 에러 (0) | 2020.12.22 |
@GetMapping , @PostMapping 등 어노테이션 import 에러 (0) | 2020.12.21 |