文章目录
配置热部署
检查是否添加开发工具依赖 spring-boot-devtools
<!--热部署-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
点击 File --> Settings,打开设置对话框 点击 Build, Execution, Deployment --> Complier,勾选 Build project automatically
点击 Advanced Settings,勾选 Allow auto-make to start even if developed application is currently running
启动项目后在浏览器中里访问http://127.0.0.1:8080/hello,如下图所示:
修改代码,无需重新启动项目,刷新页面,系统会在程序运行过程中自动编译,于是可以看到修改后程序的运行结果,如下图所示:
Thymeleaf模板引擎
启动项目后在浏览器中访问zlytest.html和hello.html页面
注:static目录下的zlytest.html能够成功访问,而templates目录下的hello.html无法访问
在HelloController中添加如下代码后,再次访问
注:static目录下的zlytest.html能够成功访问,而templates目录下的hello.html无法访问
在pom.xml中添加Thymeleaf模板引擎依赖
<!--Thymeleaf模板引擎-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
在HelloController中添加如下代码:
在浏览器中访问 http://127.0.0.1:8080/test3
在浏览器中访问 http://127.0.0.1:8080/test1
注:静态页面的return默认是跳转到static目录下,当在pom.xml中引入了thymeleaf组件,动态跳转会覆盖默认的静态跳转,默认就会跳转到templates下
在templates目录下新建hello.jsp文件
在application.properties中设置thymeleaf页面的存储路径和指定使用后缀名为.jsp的文件
测试是否能够访问后缀名为.jsp的文件