【发布时间】:2019-05-26 02:05:15
【问题描述】:
我的 Spring Boot 项目没有从 src/main/resources/templates/login.html 加载视图。但是它确实从 src/main/resources/static/index.html 加载视图。
这是我的项目结构:
我添加了简单的<a> 标签,用于在我的index.html
<div>
<a class="btn" href="login">Login</a>
</div>
登录控制器:
@RequestMapping("/login")
public String showLogin() {
System.out.println("Login method called");
return "login";
}
这个方法不会被调用。此外,我看到很多教程表明您不需要将视图添加到 static 文件夹中,只需将视图添加到 templates 文件夹中,Spring Boot 就会自动选择它。
但 Spring Boot 似乎没有从 templates 文件夹中选择视图并显示白标错误页面。
我没有使用 jsp 页面,而是使用 Thymlead 模板。
application.properties
server.servlet.context-path=/hisservices
server.port=8081
welcome.message: Welcome to the HIS Services Dashboard
WelcomeController: index.html 页面
// inject via application.properties
@Value("${welcome.message:test}")
private String message = "Hello World";
@RequestMapping("/")
public String welcome(Map<String, Object> model) {
model.put("message", this.message);
return "welcome";
}
我需要为 templates 文件夹添加显式映射吗?
【问题讨论】:
-
如果不调用控制器,则与视图无关。将您的应用程序类移动到 ...securejwt 包。
-
将
HisservicesJwtApplication.java移至外层/上层包,即com.skm.hisservice.secueejwt -
请发
HisservicesJwtApplication.java的邮编
标签: spring spring-boot