搞了几个小时,才知道springboot访问teamplates需要thymeleaf jar支持,能够处理HTML,XML,JavaScript,CSS甚至是纯文本。在pom里黏贴
org.springframework.boot
spring-boot-starter-thymeleaf

然后导入时,选择只导入改变的,import Changes如图:
在这里插入图片描述项目结构:

在这里插入图片描述application.yml文件:
spring:
mvc:
view:
suffix: /
prefix: .html

LoginController文件:
package com.hp.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class LoginController {
@RequestMapping("/login")
public ModelAndView login(){
ModelAndView modelAndView = new ModelAndView();
modelAndView.setViewName(“login”);
return modelAndView;
}

}

效果图:
在这里插入图片描述

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐