SpringBoot+FreeMarker入门

2018-09-22  本文已影响0人  inverseli

官方说明

freemarker

或多或少体现了mvc模式,能更好的进行前后端分离工作,使得前端人员和后端人员能更好的各司其职,专注与自己的技能领域,还有很多其它功能可以去官网查看文档。

入门项目

项目结构
project
pom.xml中添加依赖
    <!-- freemarker 依赖 -->
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-freemarker</artifactId>
    </dependency>
application.properties
# 不写也能正常运行
#spring.freemarker.template-loader-path=classpath:/templates/ 
#spring.mvc.view.suffix= .ftl
index.ftl
<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8" />
    <title></title>
</head>
<body>
FreeMarker模板引擎
<h1>${host}</h1>
</body>
</html>
HelloController.java
package com.inverseli.learning.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**  
 * @date:2018年9月19日 上午11:43:26    
 * @author liyuhao
 * @version 1.0   
 * @since JDK 1.8  
 * @description:  
 */
@Controller
public class HelloController {
    
    @RequestMapping("/hello")
    @ResponseBody
    public String toTest() {
        return "Hello World";
    }
    
    @RequestMapping("/")
    public String index(ModelMap map) {
        map.addAttribute("host","https://github.com/Inverseli/");
        return "index";
    }
    
}

完整项目 https://github.com/Inverseli/SpringBoot-Learning

上一篇 下一篇

猜你喜欢

热点阅读