zoukankan      html  css  js  c++  java
  • IDEA+SpringBoot+Freemark 构造一个简单的页面

    访问地址 http://localhost:8083/m2detail 

    1.在Controller中配置

    /**
         * m2detail
         */
        @RequestMapping(value = "/m2detail")
        public ModelAndView m2detail(ModelAndView modelAndView){
            modelAndView.setViewName("pc/m2detail");
            return modelAndView;
        }
    

    其中

    "/m2detail"就是URL后面的那个
    "pc/m2detail" 就是 m2detail.ftl 文件所在的路径

    2. 新建 m2detail.ftl 文件,一般多页面的项目 都会有 公共 或者 基础 的模版,当新建时,直接引入套用就可以了。这里的css,swiper等等都是其他文件夹引入的。

    主要是:
    <#import "/default/pcLayout.ftl" as myDefault> 表示要使用
    /pcLayout.ftl中定义的宏,变量... 使用方式
    <@myDefault.htmlHead 参数 x = "">
    这中间可加html
    </@myDefault.htmlHead>


    ftl语法可参考:
    http://freemarker.foofun.cn
    https://www.cnblogs.com/jpfss/p/8445200.html
    https://zhuanlan.zhihu.com/p/51270249 知乎
     
    <#import "/default/pcLayout.ftl" as myDefault>
    
    <@myDefault.htmlHead title="m2detail">
    <link rel="stylesheet" href="${basePath}/static/css/pc/m2detail.css">
    <link rel="stylesheet" href="${basePath}/static/3rd_party/swiper/swiper.min.css">
    </@myDefault.htmlHead>
    
    <@myDefault.htmlBody headType=2>
    
    这里写自己要做的内容
    
    </@myDefault.htmlBody>
    
    <@myDefault.htmlScripts>
    
    <!--<script src="${basePath}/static/js/home/home.js"></script>-->
    
    <!-- Swiper JS -->
    <script src="${basePath}/static/3rd_party/swiper/swiper.min.js"></script>
    
    <!-- Initialize Swiper -->
    <script>
    
        var swiper = new Swiper('.swiper-container', {
          slidesPerView: '2',
    
          pagination: {
            el: '.swiper-pagination',
            clickable: true,
          },
          navigation: {
            nextEl: '.swiper-button-next',
            prevEl: '.swiper-button-prev',
          },
        });
      </script>
    
    
    </@myDefault.htmlScripts>
    

    3. 写好之后,一键启动SpringBoot就行了,在网页中输入
    http://localhost:8083/m2detail 就可以了

    4. 效果图:

    此文仅为鄙人学习笔记之用,朋友你来了,如有不明白或者建议又或者想给我指点一二,请私信我。liuw_flexi@163.com/QQ群:582039935. 我的gitHub: (学习代码都在gitHub) https://github.com/nwgdegitHub/
  • 相关阅读:
    Vue-cli / webpack 加载静态js文件的方法
    shell curl 下载图片并另存为(重命名)
    sublime 技巧与快捷键篇
    es5 温故而知新 创建私有成员、私有变量、特权变量的方法
    es5 温故而知新 简单继承示例
    js 万恶之源 是否滚动到底部?
    ES6 基础知识
    jquery操作select(取值,设置选中)
    WebApi深入学习--特性路由
    Asp.net 代码设置兼容性视图
  • 原文地址:https://www.cnblogs.com/liuw-flexi/p/11981351.html
Copyright © 2011-2022 走看看