0
Spring MVCを使い始める前に、私は自分のページにwelcome.jspをロードして、プレーンテキスト(ソースのみを表示します)をロードします。これは100万回の質問です。私の解決策はXMLを使って見つけられず、私はJavaを使っています。私はまだ2つの間を切り替えるのに十分な経験はありません。Spring mvc jspがレンダリングされない
conf.class:
public class conf extends WebMvcConfigurerAdapter {
@Override
public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
configurer.enable();
}
@Bean
public InternalResourceViewResolver jspViewResolver() {
InternalResourceViewResolver bean = new InternalResourceViewResolver();
bean.setViewClass(JstlView.class);
bean.setPrefix("/views/");
bean.setSuffix(".jsp");
return bean;
}
}
ServletInitializer.class:
public class ServletInitializer extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Demo4Application.class,conf.class);
}
}
welCont.class(コントローラ):
@Controller
@RequestMapping("/spring/")
public class welCont {
@RequestMapping(method = RequestMethod.GET)
public String wel(ModelMap model)
{
model.addAttribute("test","testme");
return "welcome";
}
}
のwelcome.jsp:
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<h2>${test}</h2>
</body>
</html>