首页 > 其他 > 详细

freemarker模板引擎的各种显示

时间:2021-04-13 23:28:55      阅读:23      评论:0      收藏:0      [点我收藏+]
   <!-- freemarker https://mvnrepository.com/artifact/org.freemarker/freemarker -->
    <dependency>
      <groupId>org.freemarker</groupId>
      <artifactId>freemarker</artifactId>
      <version>2.3.31</version>
    </dependency>
    <!-- 让spring兼容freemarker https://mvnrepository.com/artifact/org.springframework/spring-context-support -->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-context-support</artifactId>
      <version>5.3.5</version>
    </dependency>
@Controller
public class IndexController {
    @Autowired
    private BookMapper bookdao;
    @GetMapping("//m1")
    public String m1(Model model){
        model.addAttribute("name","jack");
        model.addAttribute("age","18");
        model.addAttribute("isstu","true");
        model.addAttribute("birth", new Date());//new  Date.LocalDate.now()
        model.addAttribute("money", "100.985");
        model.addAttribute("loves", List.of("java","javascript","html"));


        return "test";//templates/test.ftl
    }
}

 

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <title>freemarker</title>
    <meta name="keywords" content="关键字">
    <meta name="description" content="简介">
</head>
<body>
<h2>${name!‘没有值‘}</h2>
<h2>${age}</h2>

<h2>${birth?date}----${birth?string["yyyy-MM-dd"]}</h2>

<#list loves as loves> <!--as 循环体-->
    <p>${loves}</p>
</#list>

<#if name??>
yes
    <#else >
    no
</#if>
</body>
</html>

 

freemarker模板引擎的各种显示

原文:https://www.cnblogs.com/Gu1015/p/14655152.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!