freemarker模板用例
pom.xml引入
<!--freemarker模板专用--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-freemarker</artifactId> </dependency>
2.controller调用,返回值对应templates下的*.ftl模板
@Controller @ComponentScan @EnableAutoConfiguration public class UserController { @RequestMapping("/userlist") public String userList(Map<String, Object> map) { List<User> list = userMapper.findall(); map.put("list", list); return "user"; } @Autowired private UserMapper userMapper; }
页面模板举例user.ftl
<html> <head> <title>FreeMarker的HelloWorld</title> </head> <body> <#list list as item> ID:${item.id} , 年龄${item.user_name}, 密码${item.user_password} <br> </#list> </body> </html>
.markdown-body pre,.markdown-body pre>code.hljs{color:#333;background:#f8f8f8}.hljs-comment,.hljs-quote{color:#998;font-style:italic}.hljs-keyword,.hljs-selector-tag,.hljs-subst{color:#333;font-weight:700}.hljs-literal,.hljs-number,.hljs-tag .hljs-attr,.hljs-template-variable,.hljs-variable{color:teal}.hljs-doctag,.hljs-string{color:#d14}.hljs-section,.hljs-selector-id,.hljs-title{color:#900;font-weight:700}.hljs-subst{font-weight:400}.hljs-class .hljs-title,.hljs-type{color:#458;font-weight:700}.hljs-attribute,.hljs-name,.hljs-tag{color:navy;font-weight:400}.hljs-link,.hljs-regexp{color:#009926}.hljs-bullet,.hljs-symbol{color:#990073}.hljs-built_in,.hljs-builtin-name{color:#0086b3}.hljs-meta{color:#999;font-weight:700}.hljs-deletion{background:#fdd}.hljs-addition{background:#dfd}.hljs-emphasis{font-style:italic}.hljs-strong{font-weight:700}