springboot报No mapping for GET解决方法

时间:2024-04-03 10:18:19

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

然后导入时,选择只导入改变的,import Changes如图:
springboot报No mapping for GET解决方法项目结构:

springboot报No mapping for GET解决方法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;
}

}

效果图:
springboot报No mapping for GET解决方法