java - 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>
解决方案
尝试这样做:
@RequestMapping("/show1")
public String showpage1() {
return "test";
}
其中 test.html 是您的页面
推荐阅读
- python - 如何获取某些标签值
- c - 如何在c中全局初始化变量,静态和外部有什么区别?
- flutter - 为什么 Flutter 项目中的所有文件都是红色的?为什么我在运行代码时会看到一个空白屏幕?
- android - 如何在android的系统应用程序中检测电源按钮按下
- localization - 如何在 SwiftUI 中本地化 EditButton?
- ruby-on-rails - 当尝试在本地访问我的应用程序时,我得到:“无法将主机名...转换为地址”和“名称解析暂时失败”
- php - IIS 网站 - cron/长时间执行运行时无法加载其他页面
- python - python将数据插入sqlite3表
- loops - Dafny 可以从右边验证求和元素吗?
- python - 如何在每次完成后自动运行我的 python 脚本以再次运行?