Idea创建SpringBoot项目
【File】-【new】-【Project】
创建项目
java version选择 8
选择 web、Thymeleaf
将组态文件目录拷贝到templates下,并且在application.yml文件中配置好路径
静态文件放行
@Configuration
public class ResourcesConfig extends WebMvcConfigurationSupport {
private static final String[] CLASSPATH_RESOURCE_LOCATIONS = {
"classpath:/META-INF/resources/", "classpath:/resources/",
"classpath:/static/", "classpath:/public/" ,"classpath:/templates/byzt/"};
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
//registry.addResourceHandler("/static/**").addResourceLocations("classpath:/templates/byzt/");
if (!registry.hasMappingForPattern("/webjars/**")) {
registry.addResourceHandler("/webjars/**").addResourceLocations(
"classpath:/META-INF/resources/webjars/");
}
if (!registry.hasMappingForPattern("/**")) {
registry.addResourceHandler("/**").addResourceLocations(
CLASSPATH_RESOURCE_LOCATIONS);
}
}
}
Controller·代码
@Controller
public class DemoController {
@GetMapping("/")
public String test() {
return "index_edit";
}
}
启动项目访问 http://localhost:8080/
项目已经放在服务器上,项目访问 地址