|
@@ -1,10 +1,8 @@
|
1
|
1
|
package kr.co.swh.lecture.opensource.sparkjava;
|
2
|
2
|
|
3
|
|
-import java.io.File;
|
4
|
3
|
import java.io.IOException;
|
5
|
4
|
import java.io.StringWriter;
|
6
|
5
|
|
7
|
|
-import freemarker.cache.FileTemplateLoader;
|
8
|
6
|
import freemarker.template.Configuration;
|
9
|
7
|
import freemarker.template.Template;
|
10
|
8
|
import freemarker.template.TemplateException;
|
|
@@ -14,27 +12,14 @@ import spark.TemplateEngine;
|
14
|
12
|
public class FreeMarkerTemplateEngine extends TemplateEngine {
|
15
|
13
|
|
16
|
14
|
private Configuration configuration;
|
17
|
|
- private final String PATH = "src/main/resources/freemaker";
|
18
|
|
-
|
19
|
|
- public FreeMarkerTemplateEngine() throws IOException {
|
20
|
|
-// this.configuration = createFreemarkerConfiguration();
|
21
|
|
- configuration.setClassForTemplateLoading(FreeMarkerTemplateEngine.class, "/");
|
22
|
|
- FileTemplateLoader templateLoader = new FileTemplateLoader(new File("resources"));
|
23
|
|
- configuration.setTemplateLoader(templateLoader);
|
24
|
|
-
|
25
|
|
-// Template helloTemp= configuration.getTemplate("hello.ftl");
|
26
|
|
- }
|
27
|
15
|
|
28
|
|
-// private Configuration createFreemarkerConfiguration() {
|
29
|
|
-// Configuration retVal = new Configuration();
|
30
|
|
-// retVal.setClassForTemplateLoading(FreeMarkerTemplateEngine.class, "freemarker");
|
31
|
|
-// return retVal;
|
32
|
|
-// }
|
|
16
|
+ protected FreeMarkerTemplateEngine() {
|
|
17
|
+ this.configuration = createFreemarkerConfiguration();
|
|
18
|
+ }
|
33
|
19
|
|
34
|
|
- @Override
|
35
|
|
- public String render(ModelAndView modelAndView) {
|
36
|
|
- // TODO Auto-generated method stub
|
37
|
|
- try {
|
|
20
|
+ @Override
|
|
21
|
+ public String render(ModelAndView modelAndView) {
|
|
22
|
+ try {
|
38
|
23
|
StringWriter stringWriter = new StringWriter();
|
39
|
24
|
|
40
|
25
|
Template template = configuration.getTemplate(modelAndView.getViewName());
|
|
@@ -46,5 +31,11 @@ public class FreeMarkerTemplateEngine extends TemplateEngine {
|
46
|
31
|
} catch (TemplateException e) {
|
47
|
32
|
throw new IllegalArgumentException(e);
|
48
|
33
|
}
|
49
|
|
- }
|
|
34
|
+ }
|
|
35
|
+
|
|
36
|
+ private Configuration createFreemarkerConfiguration() {
|
|
37
|
+ Configuration retVal = new Configuration();
|
|
38
|
+ retVal.setClassForTemplateLoading(FreeMarkerTemplateEngine.class, "/freemarker/"); // 수정할 것.
|
|
39
|
+ return retVal;
|
|
40
|
+ }
|
50
|
41
|
}
|