Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Spring MVC-通过Thymeleaf访问静态页面_Java_Spring_Spring Mvc_Spring Boot_Thymeleaf - Fatal编程技术网

Java Spring MVC-通过Thymeleaf访问静态页面

Java Spring MVC-通过Thymeleaf访问静态页面,java,spring,spring-mvc,spring-boot,thymeleaf,Java,Spring,Spring Mvc,Spring Boot,Thymeleaf,我有一个SpringBootWeb应用程序,使用嵌入式Tomcat+Thymeleaf模板引擎,并将其打包为可执行的JAR文件 使用的技术: 弹簧靴1.4.2.1释放, 弹簧4.3.4.释放, Thymeleaf 2.1.5.发布, Tomcat嵌入8.5.6, Maven 3, 爪哇8 我想访问位于。/src/main/resources/templates/mockups/index.html 所以我创建了这个控制器: @Controller public class MockupIndex

我有一个SpringBootWeb应用程序,使用嵌入式Tomcat+Thymeleaf模板引擎,并将其打包为可执行的JAR文件

使用的技术:

弹簧靴1.4.2.1释放, 弹簧4.3.4.释放, Thymeleaf 2.1.5.发布, Tomcat嵌入8.5.6, Maven 3, 爪哇8

我想访问位于
。/src/main/resources/templates/mockups/index.html

所以我创建了这个控制器:

@Controller
public class MockupIndexController {

    @RequestMapping("/mockup/index")
    public String welcome(Map<String, Object> model) {
        return "/mockups/index.html";
    }

}

在SpringXML配置文件中,映射静态文件的位置,请将静态文件保存在不同的文件夹中

 <mvc:resources mapping = "/mockups/**" location = "/src/main/resources/templates/mockups/" />

如果您没有使用配置文件,那么添加这个类

@Component
class WebConfigurer extends WebMvcConfigurerAdapter {
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
                registry.addResourceHandler("/mockups/**").addResourceLocations("/src/main/resources/templates/mockups/");
   }
}

我没有使用xml配置文件
 return "/mockups/index.html";
 return "redirect:/mockups/index.html";
@Component
class WebConfigurer extends WebMvcConfigurerAdapter {
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
                registry.addResourceHandler("/mockups/**").addResourceLocations("/src/main/resources/templates/mockups/");
   }
}