zoukankan      html  css  js  c++  java
  • java spring boot- freemarker 配置 yml使用流程

    1、pom.xml  加入maven 依赖

    <!-- 引入 freemarker 模板依赖 -->
    <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-freemarker</artifactId>
    </dependency>

    2、执行更新

      

    3、在application.yml 中添加 feemarker 配置

    spring:
    freemarker:
    allow-request-override: false
    cache: true
    check-template-location: true
    charset: UTF-8
    suffix: .html
    templateEncoding: UTF-8
    templateLoaderPath: classpath:/templates/
    content-type: text/html
    expose-request-attributes: false
    expose-session-attributes: false
    expose-spring-macro-helpers: false
    4、控制器代码
      
    @GetMapping(value = "/my")
        public ModelAndView my(ModelMap modelMap){
            ModelAndView mv = new ModelAndView("pay");
            modelMap.addAttribute("name","pengxingjiang");
            mv.addObject("address","四川-宜宾");
            HashMap<String,String> userInfo = new HashMap<>();
            userInfo.put("name","111");
            userInfo.put("tel","18888888888");
            mv.addObject("userInfo",userInfo);
            return mv;
    }
    

      


    5、视图文件代码
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
    </head>
    <body>
        ${name}
        ${address}
    ========
      ${userInfo.name}
      ${userInfo.tel}
    </body>
    </html>

    6、list 循环 的使用

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
    </head>
    <body>
        <#list list as item>
            <p>${item.name}-${item.tel}</p>
        </#list>
    </body>
    </html>
    

      

    @GetMapping(value = "/my")
        public ModelAndView my(ModelMap modelMap){
            ModelAndView mv = new ModelAndView("pay");
            HashMap<String,String> userInfo = new HashMap<>();
            userInfo.put("name","我的名字");
            userInfo.put("tel","18288888888");
            mv.addObject("userInfo",userInfo);
            List<HashMap> list = new ArrayList<>();
            list.add(userInfo);
            list.add(userInfo);
            list.add(userInfo);
            list.add(userInfo);
            mv.addObject("list",list);
            return mv;
    }
    

      

  • 相关阅读:
    背景样式、列表样式、变形样式、过渡动画
    边框样式、段落样式、背景样式
    属性选择符、字体样式和元素样式
    Targets选项下Other linker flags的设置
    OC金额转大写
    输入手机号码 和 金额有效性的判断
    iOS手势冲突问题
    解决iOS手势冲突问题
    iOS开发 字符串的转化 小技巧
    iOS开发添加pch文件
  • 原文地址:https://www.cnblogs.com/pxjbk/p/12010408.html
Copyright © 2011-2022 走看看