JavaのバージョンB2B2Cのソーシャル電力供給スプリングクラウド分散マイクロサービス(8)Webアプリケーションの開発(2)

設定が完了したら、上のクイックスタートプロジェクトに基づいて、Thymeleafでページをレンダリングするための簡単な例を挙げて、簡単な例を与えます。

@Controller
public class HelloController {
 
    @RequestMapping("/")
    public String index(ModelMap map) {
        // 加入一个属性,用来在模板中读取
        map.addAttribute("host", "http://blog.didispace.com");
        // return模板文件的名称,对应src/main/resources/templates/index.html
        return "index";  
    }
 
}
<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8" />
    <title></title>
</head>
<body>
<h1 th:text="${host}">Hello World</h1>
</body>
</html>

ページとして、直接htmlページショーのHello Worldを開くが、プログラムを起動した後は、http訪問:// localhostを:8080 /を、ショー値コントローラのホストである:http://blog.didispace.com、HTMLを破壊しません別の論理データ内容そのもの。

より多くのページThymeleafの構文は、公式文書Thymeleafクエリをご覧ください。

デフォルトの設定パラメータThymeleaf

あなたは、時間のデフォルト設定を変更する必要がある場合は、単純なテンプレートファイルの拡張子を変更すると、以下の属性がapplication.propertiesに変更し、必要に応じて値を変更するためにコピーし、その上のデフォルトのテンプレートのパスを変更して。

# Enable template caching.
spring.thymeleaf.cache=true 
# Check that the templates location exists.
spring.thymeleaf.check-template-location=true 
# Content-Type value.
spring.thymeleaf.content-type=text/html 
# Enable MVC Thymeleaf view resolution.
spring.thymeleaf.enabled=true 
# Template encoding.
spring.thymeleaf.encoding=UTF-8 
# Comma-separated list of view names that should be excluded from resolution.
spring.thymeleaf.excluded-view-names= 
# Template mode to be applied to templates. See also StandardTemplateModeHandlers.
spring.thymeleaf.mode=HTML5 
# Prefix that gets prepended to view names when building a URL.
spring.thymeleaf.prefix=classpath:/templates/ 
# Suffix that gets appended to view names when building a URL.
spring.thymeleaf.suffix=.html  spring.thymeleaf.template-resolver-order= # Order of the template resolver in the chain. spring.thymeleaf.view-names= # Comma-separated list of view names that can be resolved.

JSPサポートの設定
サポートJSP:春ブーツが推奨されていませんが、あなたは使用する必要がある場合は、足場として、このプロジェクトを参照することができ
、追加してくださいマイクロJAVASpringクラウドクラウドサービス構築されたB2B2Cの電子商取引プラットフォームのソースコードの分散大企業のニーズをペンギンBEG:三〇から五36247259

おすすめ

転載: blog.csdn.net/qq_42748864/article/details/95162758