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>

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM