搞了几个小时,才知道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;
}
}
效果图: