搞了几个小时,才知道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

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐