引言
在传统的web开发中通常使用jsp页面,首先需要在pom文件中引入springmvc相关的包,然后写springmvc的配置文件(包括访问资源的路径解析),之后还需再web.xml中配置访问路由。这无疑太麻烦了,每次开发前都需要编写大量的配置文件。
springboot为此提供了高效便捷的解决方案,只需再pom.xml中添加web开发的依赖,便可进行web开发,省去了繁琐的配置步骤。
下面为web开发引入的依赖
org.springframework.boot
spring-boot-starter-web
正文
那么在springboot中如果需要使用页面该怎么做呢?springboot不推荐使用jsp,因为jsp在springboot中有诸多限制,具体限制这里就不展开说了,大家感兴趣可以去网上查阅。springboot中推荐使用thymeleaf模板,使用html作为页面展示。那么如何通过Controller来访问来访问html页面呢?
1.在pom.xml文件中添加thymeleaf依赖
org.springframework.boot
spring-boot-starter-web
org.springframework.boot
spring-boot-starter-test
test
org.springframework.boot
spring-boot-starter-thymeleaf
2.在application.yml中添加访问请求配置
##thymeleaf页面模板配置
spring:
mvc:
view:
pref