一、案例

  1.1  pom.xml

<dependencies>
<!-- 除去logback支持 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency> <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- 使用log4j2,该包paren标签中已经依赖 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency> <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency> <!-- 引入freemarker包 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency> </dependencies> <build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

  1.2  application.properties

#主配置文件,配置了这个会优先读取里面的属性覆盖主配置文件的属性
spring.profiles.active=dev
server.port=8888 logging.config=classpath:log4j2-dev.xml

  1.3  编写控制器

package com.shyroke.controller;

import java.util.ArrayList;
import java.util.List; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView; @Controller
@RequestMapping(value = "/index")
public class IndexController { @RequestMapping(value = "/login")
public ModelAndView index(ModelAndView modelAndView) {
modelAndView.setViewName("index"); List<String> userList=new ArrayList<String>();
userList.add("admin");
userList.add("user1");
userList.add("user2"); modelAndView.addObject("userList", userList);
return modelAndView;
} }

  1.5  编写index.ftl

<!DOCTYPE html>
<html>
<head lang="en">
<title>Spring Boot Demo - FreeMarker</title>
<link href="/css/index.css" rel="stylesheet">
<script type="text/javascript" src="/jars/jquery-3.2.1.min.js"></script>
<script type="text/javascript" src="/js/index.js"></script>
</head>
<body>
<h2>首页<h2> <font>
<#list userList as item>
${item!}<br />
</#list>
</font> <button class="a"> click me</button>
</body>
</html>

  1.6  index.js

$(function() {
$('.a').click(function() {
alert('hello world');
});
})

  1.7  index.css

h2{color:red}

  1.8  目录结构

  • 结果

(八)SpringBoot之freeMarker基本使用的更多相关文章

  1. springboot整合freemarker

    前后端分离现在越来越多,如何有效的使用springboot来整合我们的页面是一个很重要的问题. springboot整合freemarker有以下几个步骤,也总结下我所犯的错误: 1.加依赖: 2.配 ...

  2. springboot使用Freemarker继承

    最近需要用到Freemarker的继承.但是发现没有关于springboot配置Freemarker的继承的.所以趁现在有时间写个博客. 1. Freemarker继承介绍 Freemarker 通过 ...

  3. 记springboot+mybatis+freemarker+bootstrap的使用(1)

    一..springboot的配置 1.安装并配置maven maven是项目管理工具,可以自动下载并管理jar包之间的依赖关系,可通过maven自动配置springboot 参照百度经验https:/ ...

  4. SpringBoot学习8:springboot整合freemarker

    1.创建maven项目,添加pom依赖 <!--springboot项目依赖的父项目--> <parent> <groupId>org.springframewor ...

  5. springboot整合freemarker(转)

    添加依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>sp ...

  6. springboot 使用 freemarker 无法正常跳转的问题?

    1.springboot 使用 freemarker 无法正常跳转的问题? 参考:https://blog.csdn.net/Lin_xiaofeng/article/details/79122053 ...

  7. springboot 整合 freemarker

    springboot 整合 freemarker 依赖 <parent> <groupId>org.springframework.boot</groupId> & ...

  8. SpringBoot整合freemarker 引用基础

    原 ElasticSearch学习笔记Ⅲ - SpringBoot整合ES 新建一个SpringBoot项目.添加es的maven坐标如下: <dependency> <groupI ...

  9. 【SpringBoot】09.SpringBoot整合Freemarker

    SpringBoot整合Freemarker 1.修改pom文件,添加坐标freemarker启动器坐标 <project xmlns="http://maven.apache.org ...

随机推荐

  1. javasript模块化

    模块概述 随着一个网站越来越大,html页面文件越来越多,由<script src='xxx.js'></script>引入的js文件越来越多,我们的单个js文件很大,上几万行 ...

  2. php如何生成 uuid(总结)

    php如何生成 uuid(总结) 一.总结 一句话总结: UUID的全拼为“Universally Unique Identifier”,可以译为“通用唯一识别码”. UUID是指在一台机器上生成的数 ...

  3. 数字图像处理--算术、几何、谐波、逆谐波均值滤波器Matlab

    本文链接:https://blog.csdn.net/Dooonald/article/details/78545461算术均值 close all clear all f=imread('D:/te ...

  4. C# GDI+ 简单实现图片写文字和图片叠加(水印)(转)

    using System; using System.Collections; using System.Configuration; using System.Data; using System. ...

  5. supervisor :a running process with pid = 0,程序PID为0

    Neo君作为一只小白,今天踩到了一个supervisor的坑. 如上图所示,出现这种情况后,想把这个进程停止.或者重启,甚至stop all它还是这个样子,如下图(马赛克部分为进程名称): 一:背景 ...

  6. Spring Bootz之热部署

    在项目的pom.xml文件添加如下两段 <dependency> <groupId>org.springframework.boot</groupId> <a ...

  7. 123457123456#0#-----com.twoapp.ErTongHuaHua01--前拼后广--儿童绘画填色游戏jiemei

    com.twoapp.ErTongHuaHua01----儿童绘画填色游戏jiemei

  8. 原创:Mac AppleScript 自动登录两个QQ

    前提,已有登录过的账号,且没有设置为自动登录 tell application "QQ" activate tell application "System Events ...

  9. otepad++ 配置 支持jquery、html、css、javascript、php代码提示

    官网下载:http://notepad-plus-plus.org/ 获取插件的方法:打开软件,窗口工具栏有有一个问号,点获取插件. 我使用的插件(安装方法都是官方的方法): QuickText.v0 ...

  10. php 常用正则表达 邮箱 手机号啥的

    class RegexConst { const REGEX_MOBLIE_86 = '/^1(3|4|5|7|8)\d{9}$/';//中国手机号 const REGEX_MOBLIE_852 = ...