File tree Expand file tree Collapse file tree 4 files changed +90
-0
lines changed
springboot-freemarker-sample
java/com/ipman/freemarker/sample Expand file tree Collapse file tree 4 files changed +90
-0
lines changed Original file line number Diff line number Diff line change 4444 <groupId >org.springframework.boot</groupId >
4545 <artifactId >spring-boot-starter-freemarker</artifactId >
4646 </dependency >
47+ <dependency >
48+ <groupId >com.github.andrewoma.dexx</groupId >
49+ <artifactId >dexx-collections</artifactId >
50+ <version >0.2</version >
51+ <scope >compile</scope >
52+ </dependency >
4753 </dependencies >
4854
4955 <build >
Original file line number Diff line number Diff line change 11package com .ipman .freemarker .sample .controller ;
22
3+ import com .ipman .freemarker .sample .entity .Student ;
34import org .springframework .stereotype .Controller ;
45import org .springframework .web .bind .annotation .GetMapping ;
56import org .springframework .web .servlet .ModelAndView ;
67
8+ import java .util .ArrayList ;
9+ import java .util .List ;
10+
711/**
812 * @author ipipman
913 * @version V1.0
@@ -26,4 +30,23 @@ public ModelAndView hello() {
2630 return model ;
2731 }
2832
33+ /**
34+ * 测试Freemarker对象与列表渲染
35+ */
36+ @ GetMapping ("/hello1" )
37+ public ModelAndView hello1 () {
38+ ModelAndView model = new ModelAndView ("hello1" );
39+ List <Student > list = new ArrayList <>();
40+ Student s1 = new Student ();
41+ s1 .setIdNo ("No1" );
42+ s1 .setName ("ipman" );
43+ list .add (s1 );
44+ Student s2 = new Student ();
45+ s2 .setIdNo ("No2" );
46+ s2 .setName ("ipipman" );
47+ list .add (s2 );
48+ model .addObject ("students" , list );
49+ return model ;
50+ }
51+
2952}
Original file line number Diff line number Diff line change 1+ package com .ipman .freemarker .sample .entity ;
2+
3+ /**
4+ * Created by ipipman on 2021/9/23.
5+ *
6+ * @version V1.0
7+ * @Package com.ipman.freemarker.sample.entity
8+ * @Description: (用一句话描述该文件做什么)
9+ * @date 2021/9/23 5:59 下午
10+ */
11+ public class Student {
12+
13+ private String idNo ;
14+
15+ private String name ;
16+
17+ public String getIdNo () {
18+ return idNo ;
19+ }
20+
21+ public void setIdNo (String idNo ) {
22+ this .idNo = idNo ;
23+ }
24+
25+ public String getName () {
26+ return name ;
27+ }
28+
29+ public void setName (String name ) {
30+ this .name = name ;
31+ }
32+
33+ @ Override
34+ public String toString () {
35+ return "Student{" +
36+ "idNo='" + idNo + '\'' +
37+ ", name='" + name + '\'' +
38+ '}' ;
39+ }
40+ }
Original file line number Diff line number Diff line change 1+ <!DOCTYPE html>
2+ <html lang =" en" >
3+ <head >
4+ <meta charset =" UTF-8" >
5+ <title >demo列表</title >
6+ </head >
7+ <body >
8+ <table border =" 1" >
9+ <tr >
10+ <td >编号</td >
11+ <td >名称</td >
12+ </tr >
13+ <#list students as student >
14+ <tr >
15+ <td >${student.idNo} </td >
16+ <td >${student.name} </td >
17+ </tr >
18+ </#list >
19+ </table >
20+ </body >
21+ </html >
You can’t perform that action at this time.
0 commit comments