Spring Boot (浜�): 闆嗘垚 FreeMarker 涓� Bootstrap

鍦� 銆� Spring Boot (涓�): 蹇�熸瀯寤� WebMvc 搴旂敤 銆嬩腑锛屾垜浠睍绀轰簡 Spring Boot 濡備綍蹇�熸瀯寤轰竴涓秴绠�鍗曠殑 WebMvc 搴旂敤锛堟案杩滅殑 Hello 绯诲垪锛� 233锛夈�傛帴涓嬫潵锛屾垜浠渶瑕佸姞鍏ヤ竴浜涙洿瀹為檯鐨勭壒鎬э紝闆嗘垚 FreeMarker 鍜� Bootstrap 浣滀负鍓嶇鏄剧ず銆�

鏈瘒浠g爜浠� Spring Boot (涓�): 蹇�熸瀯寤� WebMvc 搴旂敤 鏋勫缓浠g爜涓哄熀纭�銆�

浣跨敤 FreeMarker 浣滀负椤甸潰灞曠ず

  • build.gradle 涓鍔� FreeMarker 渚濊禆锛�
...java
  compile("org.springframework.boot:spring-boot-starter-freemarker")
...
  • src/main/resources 涓垱寤� application.properties 鏂囦欢锛屽唴瀹瑰涓嬶細
application.message: Hello, Boot

spring.freemarker.cache=false
spring.freemarker.charset=UTF-8
spring.freemarker.check-template-location=true
spring.freemarker.content-type=text/html
spring.freemarker.expose-request-attributes=true
spring.freemarker.expose-session-attributes=true
spring.freemarker.request-context-attribute=request
  • src/main/resources 鍒涘缓鐩綍 templates, 骞跺湪姝ょ洰褰曞垱寤� hello.ftl锛屽唴瀹瑰涓嬶細





Date: ${time?date}

Time: ${time?time}
Message: ${message}
  • 淇敼 HelloController.java:
package li.fyunli.springboot.controller;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Date;

/**
 * Created by fyunli on 16/4/1.
 */
@Controller
public class HelloController {

    @Value("${application.message:Hello World}")
    private String message = "Hello World";

    @RequestMapping("/hello")
    public String welcome(ModelMap model) {
        model.put("time", new Date());
        model.put("message", this.message);
        return "hello";
    }

}

浣夸箣鍓� @ResponseBody 杈撳嚭鏀规垚 freemarker 椤甸潰杈撳嚭锛屽苟浠� application.properties 鍙栧�煎~鍏呴〉闈€��

  • 鍚姩搴旂敤锛屾祻瑙堝櫒鎵撳紑 http://localhost:8080/hello 鏌ョ湅椤甸潰灞曠ず锛�
Spring Boot (浜�): 闆嗘垚 FreeMarker 涓� Bootstrap_第1张图片
freemarker result

Bootstrap 缇庡寲椤甸潰

  • 淇敼 hello.ftl 鍐呭濡備笅锛�
<#assign base = request.contextPath />



    
    
    
    

    
    Spring Boot - hello

    
    
    

    
    





Date: ${time?date}
Time: ${time?time}
Message: ${message}

漏2016 fyunli

  • 鍦� src/resources 涓垱寤� static/css 鐩綍锛屾坊鍔� main.css锛�
html {
    position: relative;
    min-height: 100%;
}
body {
    /* Margin bottom by footer height */
    margin-bottom: 60px;
}
.footer {
    position: absolute;
    bottom: 0;
    width: 100%;
    /* Set the fixed height of the footer here */
    height: 60px;
    background-color: #f5f5f5;
}

.container {
    width: auto;
    max-width: 680px;
    padding: 0 15px;
}
.container .text-muted {
    margin: 20px 0;
}
  • 娴忚鍣ㄦ墦寮� http://localhost:8080/hello 鏌ョ湅椤甸潰灞曠ず锛�
Spring Boot (浜�): 闆嗘垚 FreeMarker 涓� Bootstrap_第2张图片
bootstrap page

娉細Spring Boot 浼氫粠浠ヤ笅璺緞瀵绘壘闈欐�佹枃浠讹細

  • /META-INF/resources/
  • /resources/
  • /static/
  • /public/

婧愪唬鐮�

婧愪唬鐮侀摼鎺�: github

你可能感兴趣的:(Spring Boot (浜�): 闆嗘垚 FreeMarker 涓� Bootstrap)