대부분의 view페이지에서 제공하는 기능입니다.

Freemarker에서는 이렇게 사용을 합니다.

<#include "/common/copyright.ftl">


같은 경로에 파일이 존재 할때는

<#include "./common/copyright.ftl">


상위 폴더에 존재할 때는 다음과 같이,

<#include "*/common/copyright.ftl">


요렇게 사용도 가능합니다.

<#include "commons/*/footer.ftl">

 

출처 : ologist.tistory.com/m/670?category=322832

Posted by 셋부터넷
,

1. Properties 설정

1
spring.freemarker.request-context-attribute: rc
cs

 

 

2. Template에서 사용

1
${rc.getContextPath()}
cs

 

 

 

 

 

Posted by 셋부터넷
,

1. 의존성 추가

- Maven

1
2
3
4
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
cs

- Gradle

1
compile('org.springframework.boot:spring-boot-starter-freemarker')
cs

 

 

2. Properties 설정

1
2
3
4
5
6
7
8
9
10
#freemarker configs
spring.freemarker.template-loader-path=classpath:/templates
spring.freemarker.prefix=/freemarker/
spring.freemarker.suffix=.ftl
spring.freemarker.contentType=text/html
spring.freemarker.charset=UTF-8
spring.freemarker.cache=false
 
#devtools configs
spring.devtools.livereload.enabled=true
cs

※ livereload를 enable시 freemarker cache 옵션을 false로 변경하여 ftl이 변경시 자동으로 새로고침되도록 설정하며 운영시에는 반드시 cache옵션을 true로 변경

 


3. Controller 작성

1
2
3
4
5
@GetMapping("/hello")
public String hello(Map model){
    model.put("msg""hello freemarker");
    return "hello";
}
cs

 


4. Test Template 작성

1
2
3
4
5
6
7
8
9
10
11
<!DOCTYPE html>
<html lang="ko">
<head>
    <meta charset="utf-8">
    <title>hello</title>
</head>
<body>
    <h1>Freemarker Test</h1>
    <h2>${msg}</h2>
</body>
</html>
cs

 

 

Posted by 셋부터넷
,