Skip to content

Commit d381967

Browse files
add free marker
1 parent b4473d2 commit d381967

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,11 @@
112112
<groupId>org.springframework.boot</groupId>
113113
<artifactId>spring-boot-starter-actuator</artifactId>
114114
</dependency>
115+
<!--freemaker依赖 -->
116+
<dependency>
117+
<groupId>org.springframework.boot</groupId>
118+
<artifactId>spring-boot-starter-freemarker</artifactId>
119+
</dependency>
115120
</dependencies>
116121

117122
<build>

src/main/java/com/controller/HelloWordController.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,38 @@
44
import com.compont.ZzpProperties;
55
import com.dao.UserRepository;
66
import org.springframework.beans.factory.annotation.Autowired;
7-
import org.springframework.boot.autoconfigure.SpringBootApplication;
87
import org.springframework.cache.annotation.Cacheable;
98
import org.springframework.data.domain.Page;
109
import org.springframework.data.domain.PageRequest;
1110
import org.springframework.data.domain.Pageable;
1211
import org.springframework.data.domain.Sort;
12+
import org.springframework.stereotype.Controller;
1313
import org.springframework.web.bind.annotation.RequestMapping;
1414
import org.springframework.web.bind.annotation.RequestMethod;
15-
import org.springframework.web.bind.annotation.RestController;
1615

1716
import javax.servlet.http.HttpSession;
17+
import java.util.Date;
18+
import java.util.Map;
1819
import java.util.UUID;
1920

2021
/**
2122
* Created by zhuzhengping on 2017/2/1.
2223
* 第一个helloworld类
2324
*/
24-
@SpringBootApplication
25-
@RestController //注解-该类返回的都是json格式
25+
@Controller("template.freemarkerController") //注解-该类返回的都是json格式
2626
public class HelloWordController {
2727

2828
@Autowired
2929
private ZzpProperties zzpProperties;
3030
@Autowired
3131
private UserRepository userRepository;
3232

33-
@RequestMapping(value = "/hello",method = RequestMethod.GET)
34-
public String HelloWorld(){
35-
return "HelloWorld,SpringBoot!!!";
33+
@RequestMapping(value = "/template/freemarker/welcome")
34+
public String HelloWorld(Map<String,Object> map){
35+
36+
map.put("time",new Date());
37+
map.put("message","zzp");
38+
return "welcome";
3639
}
3740

3841

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<!<!doctype html>
2+
<html lang="en">
3+
<body>
4+
Date: ${time?date}<br>
5+
Message: ${message}
6+
</body>
7+
</html>

0 commit comments

Comments
 (0)