springboot-整合freemarker

一、添加依賴:pom.xmljavascript

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

二、配置文件:application.propertieshtml

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

三、controllerjava

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

四、ftl文件mysql

<!--獲取項目路徑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>
相關文章
相關標籤/搜索