1.创建一个springboot的项目
2.导入jar包
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency>
3.在templates目录下创建一个login.html页面
4.在resoures下的application.properties添加以下配置
spring.thymeleaf.prefix=classpath:/templates/ spring.thymeleaf.suffix=.html spring.thymeleaf.mode=HTML spring.thymeleaf.encoding=UTF-8 spring.thymeleaf.servlet.content-type=text/html spring.thymeleaf.cache=false
5.在启动类同级目录创建controller包并创建一个IndexController类
@Controller public class IndexController { @RequestMapping("/login") public String helloWord(){ System.out.println("hhhhhhhhhhhhhhhhh"); return "login"; } }
出现的问题的问题No static resource login.
最后找到的解决方案
在启动类上添加@ComponentScan("com.lt.crm.controller")注解