栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java > SpringBoot

SpringBoot集成FreeMarker

SpringBoot 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

SpringBoot集成FreeMarker

给大家简单介绍一下springboot 集成FreeMarker
过程很简单,5分钟即可。

首先在项目中增添依赖spring-boot-starter-freemarker
pom文件代码如下:



    4.0.0

    com.dalaoyang
    springboot_freemarker
    0.0.1-SNAPSHOT
    jar

    springboot_freemarker
    springboot_freemarker

    
 org.springframework.boot
 spring-boot-starter-parent
 1.5.10.RELEASE
  
    

    
 UTF-8
 UTF-8
 1.8
    

    
 
     org.springframework.boot
     spring-boot-starter-freemarker
 
 
     org.springframework.boot
     spring-boot-starter-web
 

 
     org.springframework.boot
     spring-boot-devtools
     runtime
 
 
     org.springframework.boot
     spring-boot-starter-test
     test
 
    

    
 
     
  org.springframework.boot
  spring-boot-maven-plugin
     
 
    

然后创建controller,代码如下:

package com.dalaoyang.controller;

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


@Controller
public class TestController {

    @RequestMapping("/test")
    public String testFreemarker(ModelMap modelMap){
 modelMap.addAttribute("msg", "Hello dalaoyang , this is freemarker");
 return "freemarker";
    }
}

application.properties如下

##端口号
server.port=8888

#设定ftl文件路径
spring.freemarker.template-loader-path=classpath:/templates
#设定静态文件路径,js,css等
spring.mvc.static-path-pattern=/static/**

然后简单给大家介绍一下,目录结构

然后贴上ftl文件的代码,一定注意,是ftl!!!!!
写html文件是无法找到页面的。




    
    FreeMarker


${msg}

然后启动项目,访问http://localhost:8888/ 即可看到以下页面,

源码下载 :大老杨码云

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/235113.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号