springboot中模板 freemark,thymeleaf,jsp

來源:互聯網
上載者:User

標籤:boot   spring   app   classpath   framework   imp   cat   util   rom   

freemark模板和thymeleaf模板1.在pom.xml中引入thymeleaf和freemark;
<dependency>            <groupId>org.springframework.boot</groupId>            <artifactId>spring-boot-starter-thymeleaf</artifactId></dependency><dependency>            <groupId>org.springframework.boot</groupId>            <artifactId>spring-boot-starter-freemarker</artifactId></dependency>

  

2.在application.xml中配置
###########################################################THYMELEAF (ThymeleafAutoConfiguration)#########################################################spring.thymeleaf.prefix=classpath:/templates/#spring.thymeleaf.suffix=.html#spring.thymeleaf.mode=HTML5#spring.thymeleaf.encoding=UTF-8# ;charset=<encoding> is added#spring.thymeleaf.content-type=text/html # set to false for hot refreshspring.thymeleaf.cache=false ###########################################################FREEMARKER (FreeMarkerAutoConfiguration)########################################################spring.freemarker.allow-request-override=falsespring.freemarker.cache=truespring.freemarker.check-template-location=truespring.freemarker.charset=UTF-8spring.freemarker.content-type=text/htmlspring.freemarker.expose-request-attributes=falsespring.freemarker.expose-session-attributes=falsespring.freemarker.expose-spring-macro-helpers=false#spring.freemarker.prefix=#spring.freemarker.request-context-attribute=#spring.freemarker.settings.*=#spring.freemarker.suffix=.ftl#spring.freemarker.template-loader-path=classpath:/templates/ #comma-separated list#spring.freemarker.view-names= # whitelist of view names that can be resolved

  

3.編寫模板
//注意路徑是在配置中預設的,也是可以修改的<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3">    <head>        <title>Hello World!</title>    </head>    <body>        <h1 th:inline="text">Hello.v.2</h1>        <p th:text="${hello}"></p>    </body></html>--------freemark模板入下<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3">    <head>        <title>Hello World!</title>    </head>    <body>        <h1>Freemark</h1>        <p>${hello}</p>    </body></html>

  

4.controller層
package com.ithuan.demo.controller;import java.util.Map;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;@Controller//@RequestMapping("/templates")public class TemplateController {@RequestMapping("/hello1111")public String hello1(Map<String,Object> map){System.err.println("----");map.put("hello","from TemplateController.helloHtml");return "hello1";}@RequestMapping("/hello22")public String hello22(Map map){System.err.println("2222");map.put("hello", "最終的大boss");return "freemakr";}}

  

jsp頁面展內建的解析不再展示

springboot中模板 freemark,thymeleaf,jsp

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.