前回の続き
bootstrapやjQueryを追加したいと思いWebJarsを追加した。
環境
- Mac High Sierra 10.13.5
- Java 1.8.0_11
- Maven 3.5.4
- springboot 2.0.3
手順
WebJarsで、pom.xmlに記載する内容を確認し、追加。
pom.xml
<dependency>
<groupId>org.webjars</groupId>
<artifactId>bootstrap</artifactId>
<version>4.1.1</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>jquery</artifactId>
<version>3.3.1</version>
</dependency>
htmlを修正。以下3行を追加し、とりあえず文字を青くした。
<link rel="stylesheet" href="webjars/bootstrap/4.1.1/css/bootstrap.min.css" />
<script src="webjars/bootstrap/4.1.1/js/bootstrap.min.js"></script>
<p class="text-primary" th:text="${hello}"></p>
追加後のhtml
index.html
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>index page</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta charset="UTF-8" />
<link rel="stylesheet" href="webjars/bootstrap/4.1.1/css/bootstrap.min.css" />
<script src="webjars/bootstrap/4.1.1/js/bootstrap.min.js"></script>
</head>
<body>
<p>index page</p>
<p class="text-primary" th:text="${hello}"></p>
</body>
</html>
cssとjsのディレクトリを作成。
src/main/resources/static/css
src/main/resources/static/js
jarファイルを作成し、起動。
Hello World !の文字が青くなっていれば成功。