首页 > 编程语言 > 详细

SpringBoot编写html并热部署

时间:2020-06-29 14:57:39      阅读:60      评论:0      收藏:0      [点我收藏+]

1、下载htmleditor插件:eclipse-->help-->Eclipse MarketPlace-->HtmlEditor,下载完成后重启eclipse。

2、添加依赖及配置文件:

     ①热部署依赖:

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>

 

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<!--devtools热部署 -->
<configuration>
<fork>true</fork>
<addResources>true</addResources>
</configuration>
</plugin>
</plugins>
</build>

    ②热部署配置(.properties文件):

spring.devtools.restart.enabled=true

    ③采用Thymeleaf模板引擎,因此需要添加Thymeleaf依赖:

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>

    ④配置Thymeleaf要加载的文件(.properties文件):

spring.thymeleaf.prefix=classpath:/templates/

3、编写@Controller,以访问html文件:

package com.zr.ams.demo;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

@Controller
public class LoginController {
@GetMapping("login")
public String login12() {
return "index";
}

}

4、编写html文件(建议把脚本放在 <body> 元素的底部。这会提高网页加载速度,因为 HTML 加载不受制于脚本加载。

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script src="/js/angular.min.js"></script>

</head>
<body>
<div ng-app="">
<p>名字 : <input type="text" ng-model="name"></p>
<h1>Hello {{name}}</h1>
</div>
</body>
</html>

5、springboot项目默认是不允许直接访问template下的文件的,是受保护的。若想直接访问html文件,而不通过Controller层,则可通过以下配置完成(.properties文件):

spring.resources.static-locations=classpath:/templates/

6、templates下的html若无法访问static下的css,js类似,需做如下配置(.properties文件):
spring.resources.static-locations=classpath:/templates/,classpath:/static/

SpringBoot编写html并热部署

原文:https://www.cnblogs.com/paddy-gfx/p/13207685.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!