springBoot---优化ftlh

1.详情见下图

 

 

 

 

 

 

 

 

 

 

my:
user: zhangsan
age: 23
spring:
freemarker:
allow-request-override: true
allow-session-override: true
cache: false
check-template-location: true
charset: UTF-8
content-type: text/html;
expose-request-attributes: true
expose-session-attributes: true
expose-spring-macro-helpers: true
template-loader-path: classpath:/templates/,classpath:/static/,classpath:/public/
prefix:
suffix: .ftlh
request-context-attribute: request
settings:
template_update_delay: 0
url_escaping_charset: UTF-8
locale: UTF-8
datetime_format: yyyy-MM-dd HH:mm:ss
date_format: yyyy-MM-dd
time_format: HH:mm:ss
template_exception_handler: html_debug
# 数字格式化,无小数点
number_format: '0.#'
# 设置freemarker标签 0,1,2 0=自动识别,默认1
tag_syntax: 'auto_detect'




<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
我的名字是: ${name}
性别是:${sex}
年龄是:${age}
<#if sex=='0'>

<#elseif sex=='1'>

<#else >
飞哥
</#if>
<#if age gte 18>
已成年
<#else >
未成年
</#if>
<#list userList as user>
${user}
</#list>
</body>
</html>



package demo.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.Map;

@Controller
public class FreemarkerIndexController {
@RequestMapping("/freemarkerIndex")
public String freemarkerIndex(Map<String,Object> result, HttpServletRequest request){
result.put("name","hello");
result.put("sex","0");
result.put("age",20);
ArrayList<String> userList=new ArrayList<>();
userList.add("小桃子");
userList.add("小丽丽");
result.put("userList",userList);
return "freemarkerIndex";
}
}




package demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;

@SpringBootApplication
//@ComponentScan("demo")
public class demoApplication {
public static void main(String[] args){
SpringApplication.run(demoApplication.class);
}
}

 

posted @ 2021-01-06 11:04  沫笙*  阅读(415)  评论(0编辑  收藏  举报