1.导入依赖
org.springframework
spring-webmvc
5.3.1
ch.qos.logback
logback-classic
1.2.3
javax.servlet
javax.servlet-api
3.1.0
provided
org.thymeleaf
thymeleaf-spring5
3.0.12.RELEASE
2.在web.xml中配置Spring前端控制器DispatherServlet
DispatcherServlet org.springframework.web.servlet.DispatcherServlet contextConfigLocation classpath:springmvc.xml DispatcherServlet /
3.编写Controller层使用注解和配置文件方式交给IOC管理
@Controller
public class HelloController {
@RequestMapping(value = "/") //匹配访问的虚拟路径前缀主机地址+项目名
public String index(){
return "index";//返回thymeleaf视图解析器对应的视图
}
}
4.在前端控制器指定的配置文件中,配置包扫描和视图解析器
xmlns:th="http://www.thymeleaf.org" //thymeleaf的命名空间在html文件加入
4.创建视图配置tomcat服务器
xmlns是thymeleaf的约束
Title
Welcome to Springmvc first html
5.启动Tomcat访问即可
注意事项:
在java中写路径服务器会自动的拼接到项目名后面
、 在html中写路径,路径会拼接到浏览器访问路径的后面



