首页 > 解决方案 > Spring-boot restapi 页面调用

问题描述

我有一个简单的弹簧启动应用程序。我正在尝试通过休息控制器加载 html 文件。下面是我的文件夹结构。我无法加载 test.html(就像里面的 helloworld 代码一样)

在此处输入图像描述

@RequestMapping("/show1")
public ModelAndView showpage1() {
    System.out.println("## show1");
    ModelAndView modelAndView = new ModelAndView();
     modelAndView.setViewName("test");
     return modelAndView;
}

我的 test.html 内容

<h1> hello World </h1>

标签: javarestspring-boot

解决方案


尝试这样做:

 @RequestMapping("/show1")
            public String showpage1() {
                return "test";
            } 

其中 test.html 是您的页面


推荐阅读