zoukankan      html  css  js  c++  java
  • springboot-整合freemarker

    1、添加依赖:pom.xml

    <!--freemarker依赖,模板引擎-->
        <dependency>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-freemarker</artifactId>
        </dependency>

    2、配置文件:application.properties

    spring.datasource.url=jdbc:mysql://127.0.0.1:3306/mysql-boot
    spring.datasource.username=root
    spring.datasource.password=123123
    spring.datasource.driver-class-name=com.mysql.jdbc.Driver
    
    spring.freemarker.suffix=.ftl
    spring.freemarker.templateEncoding=UTF-8
    spring.freemarker.templateLoaderPath=classpath:/templates/
    spring.freemarker.content-type=text/html
    spring.freemarker.request-context-attribute=request

    3、controller

    @RequestMapping("getStudents/{name}")
        public String getStudents(ModelMap map, @PathVariable String name){
            .....
            return "views/student";
        }

    4、ftl文件

    <!--获取项目路径springMacroRequestContext或${request.contextPath}-->
        <#assign path= springMacroRequestContext.getContextPath()/>
        <script src="${path}/js/jquery.js" type="text/javascript"></script><script src="${request.contextPath}/js/jquery.js" type="text/javascript"></script>
  • 相关阅读:
    JVM底层原理 内存模型+GC垃圾回收
    新Socket与网络小结
    Redis五大数据结构及基本指令用法
    MySql高级汇总-事务,索引,SQL调优,分库分表,读写分离
    笔试错题整理
    设计模式(思路)
    网络编程
    linux
    基础算法--KMP匹配字符串
    基础算法--整数二分
  • 原文地址:https://www.cnblogs.com/lijianda/p/11052530.html
Copyright © 2011-2022 走看看