最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

SpringBoot整合Freemarker的基本步驟

 更新時(shí)間:2022年02月10日 11:26:48   作者:星辰之力  
這篇文章主要介紹了SpringBoot整合Freemarker的基本步驟,添加依賴及添加相關(guān)配置的實(shí)例代碼詳解,代碼簡(jiǎn)單易懂,對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下

添加pom依賴

<!-- springboot整合freemarker -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>

在application.yml中添加相關(guān)配置

# 配置freemarker
spring:
  freemarker:
    # 設(shè)置模板后綴名
    suffix: .ftl
    # 設(shè)置文檔類型
    content-type: text/html
    # 設(shè)置頁(yè)面編碼格式
    charset: UTF-8
    # 設(shè)置頁(yè)面緩存
    cache: false
    # 設(shè)置ftl文件路徑
    template-loader-path:
      - classpath:/templates
  # 設(shè)置靜態(tài)文件路徑,js,css等
  mvc:
    static-path-pattern: /static/**

創(chuàng)建freemarker模板

目錄:src/main/resources 創(chuàng)建templates文件夾,文件夾里新建freemarker.ftl文件

<!DOCTYPE>
<html>
    <head>
        <title>freemark</title>
    </head>
    <body>
        <h1>Hello ${name} from resource freemark!</h1>
    </body>
</html>

創(chuàng)建控制層

package com.ahut.action;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
/**
 * 
 * @ClassName: FreemarkerAction
 * @Description: freemarker控制層
 * @author cheng
 * @date 2018年1月22日 下午8:19:39
 */
@Controller
@RequestMapping(value = "/freemarker")
public class FreemarkerAction {
    /**
     * 日志管理
     */
    private static Logger log = LoggerFactory.getLogger(FreemarkerAction.class);
     * 
     * @Title: toDemo
     * @Description: 跳轉(zhuǎn)freemarker頁(yè)面
     * @param mv
     * @return
    @RequestMapping(value = "/toDemo")
    public ModelAndView toDemo(ModelAndView mv) {
        log.info("====>>跳轉(zhuǎn)freemarker頁(yè)面");
        mv.addObject("name", "jack");
        mv.setViewName("freemarker");
        return mv;
    }
}

測(cè)試訪問(wèn)

啟動(dòng)項(xiàng)目,輸入http://localhost:8080/freemarker/toDemo,看到以下界面

Freemarker獲取項(xiàng)目根路經(jīng)

application.properties

spring.freemarker.request-context-attribute=request

ftl

<#assign base=request.contextPath />
<!DOCTYPE html>
<html lang="zh">
<head>
    <base id="base" href="${base}" rel="external nofollow" >
    <title>首頁(yè)</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <link href="${base}/static/bootstrap-3.3.4/css/bootstrap.min.css" rel="external nofollow"  rel="stylesheet">
    <script src="${base}/static/bootstrap-3.3.4/js/bootstrap.min.js"></script>

js

var base = document.getElementById("base").href;
// 與后臺(tái)交互
_send = function(async, url, value, success, error) {
    $.ajax({
        async : async,
        url : base + '/' + url,
        contentType : "application/x-www-form-urlencoded; charset=utf-8",
        data : value,
        dataType : 'json',
        type : 'post',
        success : function(data) {
            success(data);
        },
        error : function(data) {
            error(data);
        }
    });
};

Springboot配置靜態(tài)資源

package com.ahut.config;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
/**
 * @author cheng
 * @className: WebConfig
 * @description: 靜態(tài)資源配置類
 * @dateTime 2018/4/19 17:59
 */
@Configuration
@EnableWebMvc
public class WebConfig extends WebMvcConfigurerAdapter {
    /**
     * 日志管理
     */
    private Logger log = LoggerFactory.getLogger(WebConfig.class);
     * @description:
     * @author cheng
     * @dateTime 2018/4/19 17:59
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        log.info("配置靜態(tài)資源所在目錄");
        // 和頁(yè)面有關(guān)的靜態(tài)目錄都放在項(xiàng)目的static目錄下
        registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
    }
}

Freemarker頁(yè)面引用靜態(tài)資源(CSS、JS)

<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>SpringBoot - 登錄</title>
    <meta name="keywords" content="springboot">
    <meta name="description" content="SpringBoot">
    <link rel="shortcut icon" href="favicon.ico" rel="external nofollow" >
    <link href="/static/css/bootstrap.min.css?v=3.3.6" rel="external nofollow"  rel="stylesheet" type="text/css">
    <link href="/static/css/font-awesome.css?v=4.4.0" rel="external nofollow"  rel="stylesheet">
    <!-- Sweet Alert -->
    <link href="/static/css/plugins/sweetalert/sweetalert.css" rel="external nofollow"  rel="stylesheet">
    <link href="/static/css/animate.css" rel="external nofollow"  rel="stylesheet">
    <link href="/static/css/style.css?v=4.1.0" rel="external nofollow"  rel="stylesheet">
    <!--[if lt IE 9]>
    <meta http-equiv="refresh" content="0;ie.html"/>
    <![endif]-->
    <script>if (window.top !== window.self) {
        window.top.location = window.location;
    }</script>
</head>
<body class="gray-bg">
<div class="middle-box text-center loginscreen  animated fadeInDown">
    <div>
        <div>
            <h1 class="logo-name">Spring</h1>
        </div>
        <h3>歡迎使用 SpringBoot</h3>
        <div class="form-group">
            <input type="text" id="userAccount" class="form-control" placeholder="用戶名" required="">
            <input type="password" id="userPassword" class="form-control" placeholder="密碼" required="">
        <button class="btn btn-primary block full-width m-b" onclick="login()">登 錄</button>
        <p class="text-muted text-center"><a href="login.ftl#" rel="external nofollow" >
            <small>忘記密碼了?</small>
        </a> | <a href="register.html" rel="external nofollow" >注冊(cè)一個(gè)新賬號(hào)</a>
        </p>
    </div>
</div>
<!-- 全局js -->
<script src="/static/js/jquery.min.js?v=2.1.4"></script>
<script src="/static/js/bootstrap.min.js?v=3.3.6"></script>
<!-- Sweet alert -->
<script src="/static/js/plugins/sweetalert/sweetalert.min.js"></script>
<script>
    // 登錄
    function login() {
        var userAccount = $("#userAccount").val();
        var userPassword = $("#userPassword").val();
        if (userAccount == "") {
            return false;
        }
        if (userPassword == "") {
        // 登錄
        $.ajax({
            url: "/v1/login",
            type: "GET",
            data: {
                userAccount: userAccount,
                userPassword: userPassword
            },
            success: function (data) {
                if ("SUCCESS" == data.type) {
                    // 成功
                    swal({
                        title: "登錄成功",
                        timer: 1000,
                        type: "success",
                        showConfirmButton: false
                    });
                } else if ("FAIL" == data.type) {
                    // 失敗
                        title: data.msg,
                        type: "error",
                }
            }
        })
    }
</script>
</body>
</html>

到此這篇關(guān)于SpringBoot整合Freemarker的基本步驟的文章就介紹到這了,更多相關(guān)SpringBoot整合Freemarker內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • IDEA 錯(cuò)誤 No main class specified的問(wèn)題

    IDEA 錯(cuò)誤 No main class specified的問(wèn)題

    這篇文章主要介紹了IDEA 錯(cuò)誤 No main class specified的問(wèn)題,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2021-04-04
  • Java回溯法解決全排列問(wèn)題流程詳解

    Java回溯法解決全排列問(wèn)題流程詳解

    從n個(gè)不同元素中任取m(m≤n)個(gè)元素,按照一定的順序排列起來(lái),叫做從n個(gè)不同元素中取出m個(gè)元素的一個(gè)排列。當(dāng)m=n時(shí)所有的排列情況叫全排列。這篇文章主要介紹了Java回溯法解決全排列問(wèn)題
    2022-10-10
  • JavaWeb之會(huì)話技術(shù)案例詳解

    JavaWeb之會(huì)話技術(shù)案例詳解

    這篇文章主要介紹了JavaWeb之會(huì)話技術(shù)案例詳解,本篇文章通過(guò)簡(jiǎn)要的案例,講解了該項(xiàng)技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下
    2021-07-07
  • Java隨機(jī)數(shù)算法原理與實(shí)現(xiàn)方法實(shí)例詳解

    Java隨機(jī)數(shù)算法原理與實(shí)現(xiàn)方法實(shí)例詳解

    這篇文章主要介紹了Java隨機(jī)數(shù)算法原理與實(shí)現(xiàn)方法,簡(jiǎn)單分析了隨機(jī)數(shù)算法的原理并結(jié)合具體實(shí)例形式給出了java編程計(jì)算隨機(jī)數(shù)的具體操作技巧,需要的朋友可以參考下
    2017-09-09
  • SpringBoot項(xiàng)目設(shè)置斷點(diǎn)debug調(diào)試無(wú)效忽略web.xml問(wèn)題的解決

    SpringBoot項(xiàng)目設(shè)置斷點(diǎn)debug調(diào)試無(wú)效忽略web.xml問(wèn)題的解決

    這篇文章主要介紹了SpringBoot項(xiàng)目設(shè)置斷點(diǎn)debug調(diào)試無(wú)效忽略web.xml問(wèn)題的解決,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-08-08
  • SpringBoot多環(huán)境日志配置方式

    SpringBoot多環(huán)境日志配置方式

    SpringBoot?默認(rèn)使用LogBack日志系統(tǒng),默認(rèn)情況下,SpringBoot項(xiàng)目的日志只會(huì)在控制臺(tái)輸入,本文給大家介紹SpringBoot多環(huán)境日志配置方式,需要的朋友可以參考下
    2024-08-08
  • Java執(zhí)行hadoop的基本操作實(shí)例代碼

    Java執(zhí)行hadoop的基本操作實(shí)例代碼

    這篇文章主要介紹了Java執(zhí)行hadoop的基本操作實(shí)例代碼的相關(guān)資料,需要的朋友可以參考下
    2017-04-04
  • 從架構(gòu)思維角度分析分布式鎖方案

    從架構(gòu)思維角度分析分布式鎖方案

    這篇文章主要介紹了從架構(gòu)與思維的角度來(lái)分析分布式鎖的方案,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-01-01
  • springboot整合企微webhook機(jī)器人發(fā)送消息提醒

    springboot整合企微webhook機(jī)器人發(fā)送消息提醒

    這篇文章主要為大家介紹了springboot整合企微webhook機(jī)器人發(fā)送消息提醒,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-12-12
  • 利用gson將map轉(zhuǎn)為json示例

    利用gson將map轉(zhuǎn)為json示例

    這篇文章主要介紹了利用gson將map轉(zhuǎn)為json示例,需要的朋友可以參考下
    2014-05-05

最新評(píng)論

论坛| 石台县| 铜山县| 曲松县| 柏乡县| 台山市| 北海市| 旅游| 顺平县| 怀仁县| 交城县| 保德县| 建宁县| 繁昌县| 文化| 洪泽县| 铁岭县| 莱阳市| 磐安县| 新河县| 青神县| 宁津县| 兴化市| 延庆县| 莫力| 南溪县| 宝坻区| 尉氏县| 鄂托克旗| 普兰店市| 合水县| 白河县| 柘城县| 亳州市| 陆川县| 沙雅县| 房产| 晋江市| 祁东县| 奉节县| 西宁市|