如果我只需要.jsp
作为我的网络应用程序中的视图,那么我写下这样的内容:
@EnableWebMvc
@ComponentScan("com.test")
public class WebConfig extends WebMvcConfigurerAdapter {
@Bean
public ViewResolver viewResolver() {
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setPrefix("/WEB-INF/pages/");
resolver.setSuffix(".jsp");
return resolver;
}
}
是否也可以使用.html
?例如:
@Controller
public class HelloController {
@RequestMapping(value = "/hello", method = RequestMethod.GET)
public String printHello(ModelMap model) {
model.addAttribute("message", "Hello Spring MVC Framework!");
return "hello"; // uses jsp extension
}
}
@Controller
public class HomeController {
@RequestMapping(value = "/home", method = RequestMethod.GET)
public String home() {
return "home"; // uses html extension
}
}