11package com .ipman .freemarker .sample .controller ;
22
33import com .ipman .freemarker .sample .entity .Student ;
4+ import freemarker .template .Template ;
5+ import freemarker .template .TemplateException ;
6+ import org .springframework .beans .factory .annotation .Autowired ;
47import org .springframework .stereotype .Controller ;
8+ import org .springframework .ui .freemarker .FreeMarkerTemplateUtils ;
59import org .springframework .web .bind .annotation .GetMapping ;
10+ import org .springframework .web .bind .annotation .RestController ;
611import org .springframework .web .servlet .ModelAndView ;
12+ import org .springframework .web .servlet .view .freemarker .FreeMarkerConfigurer ;
713
14+ import java .io .IOException ;
815import java .util .ArrayList ;
916import java .util .List ;
1017
1724 * @date 2021/9/23 5:28 下午
1825 */
1926@ Controller
20- public class HelloWorld {
27+ public class Demo {
2128
2229 /**
2330 * 测试Freemarker模版
2431 */
25- @ GetMapping ("/hello " )
26- public ModelAndView hello () {
27- ModelAndView model = new ModelAndView ("hello " );
32+ @ GetMapping ("/demo " )
33+ public ModelAndView demo () {
34+ ModelAndView model = new ModelAndView ("demo " );
2835 model .addObject ("userName" , "ipman" );
2936 // 返回模板名称
3037 return model ;
@@ -33,9 +40,9 @@ public ModelAndView hello() {
3340 /**
3441 * 测试Freemarker对象与列表渲染
3542 */
36- @ GetMapping ("/hello1 " )
37- public ModelAndView hello1 () {
38- ModelAndView model = new ModelAndView ("hello1 " );
43+ @ GetMapping ("/demo1 " )
44+ public ModelAndView demo1 () {
45+ ModelAndView model = new ModelAndView ("demo1 " );
3946 List <Student > list = new ArrayList <>();
4047 Student s1 = new Student ();
4148 s1 .setIdNo ("No1" );
@@ -49,4 +56,5 @@ public ModelAndView hello1() {
4956 return model ;
5057 }
5158
59+
5260}
0 commit comments