Spring/Spring boot icia 70일차

Spring boot css나 script 파일화시키기

swkn 2023. 6. 1. 09:10

항상 bootstrap을 사용할 때 head 태그 안에 link나 script로 태그를 항상 붙여놓게 됬는데

이것도 incloud처럼 태그 하나로 묶어서 쓸 수 있다.

<!DOCTYPE html>
<html lang="en" xmlns::th="http://www.thymeleaf.org">
  <th:block :th:fragment="config">
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="/static/css/main.css">
  </th:block>
<body>

</body>
</html>

componant 폴더에 config.html 파일을 만들어서 위와 같이 코드를 저장했다.

main.css를 여러군데에서 사용할 때 유용할 수 있다.

 

<html lang="en" xmlns::th="http://www.thymeleaf.org">
<head>
    <th:block th:replace="component/config :: config"></th:block>
</head>

위와 같이 작성하기만 해도 config.html 안에 작성했던 내용들이 작성되게 된다.