モーダルを閉じる工作HardwareHub ロゴ画像

工作HardwareHubは、ロボット工作や電子工作に関する情報やモノが行き交うコミュニティサイトです。さらに詳しく

利用規約プライバシーポリシー に同意したうえでログインしてください。

Spring Boot における Thymeleaf サンプルコード

モーダルを閉じる

ステッカーを選択してください

お支払い手続きへ
モーダルを閉じる

お支払い内容をご確認ください

購入商品
」ステッカーの表示権
メッセージ
料金
(税込)
決済方法
GooglePayマーク
決済プラットフォーム
確認事項

利用規約をご確認のうえお支払いください

※カード情報はGoogleアカウント内に保存されます。本サイトやStripeには保存されません

※記事の執筆者は購入者のユーザー名を知ることができます

※購入後のキャンセルはできません

作成日作成日
2017/05/27
最終更新最終更新
2021/09/04
記事区分記事区分
一般公開

目次

    Spring Bootでの実用的な機能をわかりやすく解説中

    Rails における ERB と同様に、Spring Boot でもテンプレートエンジンを利用できます。今回は特に Thymeleaf (タイムリーフ) のサンプルコードをまとめます。

    公式ドキュメント

    サンプルプロジェクト構成

    .
    |-- build.gradle
    |-- gradle
    |   `-- wrapper
    |       |-- gradle-wrapper.jar
    |       `-- gradle-wrapper.properties
    |-- gradlew
    |-- gradlew.bat
    `-- src
        `-- main
            |-- java
            |   `-- hello
            |       |-- Application.java
            |       `-- GreetingController.java
            `-- resources
                |-- static
                |   `-- index.html
                `-- templates
                    `-- greeting.html
    

    build.gradle

    buildscript {
        ext {
            springBootVersion = '1.5.3.RELEASE'
        }
        repositories {
            mavenCentral()
        }
        dependencies {
            classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
        }
    }
    
    apply plugin: 'java'
    apply plugin: 'eclipse'
    apply plugin: 'idea'
    apply plugin: 'org.springframework.boot'
    
    jar {
        baseName = 'gs-serving-web-content'
        version =  '0.1.0'
    }
    
    repositories {
        mavenCentral()
    }
    
    sourceCompatibility = 1.8
    targetCompatibility = 1.8
    
    dependencies {
        // `spring-boot-starter-web` に依存するため、`spring-boot-starter-web` を明記する必要はありません。
        // https://github.com/spring-projects/spring-boot/blob/v1.5.3.RELEASE/spring-boot-starters/spring-boot-starter-thymeleaf/pom.xml#L27
        compile('org.springframework.boot:spring-boot-starter-thymeleaf')
    
        // 開発時に便利な機能を利用できるようにします。
        compile('org.springframework.boot:spring-boot-devtools')
    }
    

    Java ソースコード

    Application.java

    Spring Boot のエントリーポイントとなるクラスです。

    package hello;
    
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    
    @SpringBootApplication
    public class Application {
    
        public static void main(String[] args) {
            SpringApplication.run(Application.class, args);
        }
    }
    

    GreetingController.java

    package hello;
    
    import org.springframework.stereotype.Controller;
    import org.springframework.ui.Model;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RequestParam;
    //import org.springframework.web.bind.annotation.RequestMethod;
    
    @Controller
    public class GreetingController {
    
        @RequestMapping("/greeting") // HTTP GET/POST/PUT/PATCH/DELETE などすべてマッピングされます。
        // @RequestMapping(path = "/greeting", method = RequestMethod.GET) // GET だけをマッピングする場合の記法
        public String greeting(@RequestParam(value="name", required=false, defaultValue="World") String name, Model model) {
            model.addAttribute("name", name);
            // `src/main/resources/templates/` 内の View ファイル名を指定します。
            // メソッド名や `@RequestMapping` で指定したパス名と一致する必要はありません。
            return "greeting";
        }
    }
    
    項目 概要
    @Controller メソッドに @RequestMapping アノテーションを設定するクラスに付与します。
    @RequestMapping("/greeting") HTTP リクエスト /greeting を処理するアクションメソッドとして設定します。
    @RequestParam アノテーションが設定された引数 String name に対して、HTTP リクエスト内の value="name" パラメータを代入します。required=false となっているため、HTTP リクエスト内に存在する必要はなく、既定値は defaultValue="World" です。
    model.addAttribute("name", name) Thymeleaf テンプレート内で name という名称で変数 name の値を参照できるようにします。

    Optional を利用しても required=false 相当の設定ができます。

    public String greeting(@RequestParam(value="name") Optional<String> name, Model model) {
        model.addAttribute("name", name.orElse("World"));
        return "greeting";
    }
    

    HTML ファイル

    index.html

    通常の HTML ファイルは static ディレクトリに格納します。

    <!DOCTYPE HTML>
    <html>
    <head>
      <title>Getting Started: Serving Web Content</title>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    </head>
    <body>
      <p>Get your greeting <a href="/greeting">here</a></p>
    </body>
    </html>
    

    greeting.html (本ページの目的となる Thymeleaf のサンプルコード)

    Thymeleaf の機能を用いて <p th:text="'Hello, ' + ${name} + '!'" /> を動的に生成しています。th:textdata-th-text としても機能します。前者は html タグ内の xmlns:th="http://www.thymeleaf.org" を記述しないと IDE が警告を表示しますが、後者は HTML5 の記法であるため、警告されません。公式ドキュメントに合わせて、本ページでは前者を利用します。

    <!DOCTYPE HTML>
    <html xmlns:th="http://www.thymeleaf.org">
    <head>
      <title>Getting Started: Serving Web Content</title>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    </head>
    <body>
      <p th:text="'Hello, ' + ${name} + '!'" />
    </body>
    </html>
    

    アプリケーションの実行

    ./gradlew build
    java -jar build/libs/gs-serving-web-content-0.1.0.jar
    (or ./gradlew bootRun  ←spring-boot-devtools を利用する場合はこちら)
    

    以下の URL にアクセスしてみましょう。

    http://localhost:8080/
    http://localhost:8080/greeting
    http://localhost:8080/greeting?name=xxxxx

    spring-boot-devtools について

    Spring Boot は Java アプリケーションのため、「コードの変更、ビルド、アプリケーション再起動、ブラウザリロード」の一連のサイクルを回すための時間がかかります。spring-boot-devtools を導入すると、開発時において、以下のような事項が改善されます。ただし、java -jar での実行時などは production 環境扱いとなるため、以下の機能は有効になりません。

    • テンプレートエンジンのキャッシュが無効化されます。
    • クラスパス内のクラスファイル .class が変更されると、アプリケーションが自動で再起動されるようになります。
      • ソースコード .java はクラスパス外のファイルです。
    • クラスパス内の static や templates 配下のリソースファイル変更時は、アプリケーションは再起動されません。

    Eclipse の起動設定 (bootRun が正常に機能しない場合)

    1. 実行構成を開く
    2. 「Java アプリケーション」に新規追加
    3. Main クラスを hello.Application に設定して適用

    辞書ファイルの利用

    Rails の多言語対応と同様の機能が Thymeleaf にも存在します。既定では以下のファイルが参照されます。ブラウザの言語設定を切り替えることで表示確認できます。

    src/main/resources/messages.properties (ja,en に存在しない場合の既定値)

    hello.sub=Hello world default
    

    src/main/resources/messages_ja.properties (日本語; UTF-8 で保存すれば native2ascii で変換する必要はありません。文字化けする場合は、Eclipse 設定における「General → Content Types → Content types → Text → Java Properties File → Default encoding → UTF-8 → Update → OK」で解消します)

    hello.sub=こんにちは世界
    

    src/main/resources/messages_en.properties (英語)

    hello.sub=Hello world en
    

    greeting.html

    <p th:text="#{hello.sub}" />
    

    変数の利用

    messages.properties

    hello.sub=Hello {0} and {1}
    

    GreetingController.java

    model.addAttribute("msgKey", "hello.sub");
    model.addAttribute("name1", "aaa");
    model.addAttribute("name2", "bbb");
    

    greeting.html

    <p th:text="#{hello.sub(${name1}, ${name2})}" />
    <p th:text="#{${msgKey}(${name1}, ${name2})}" />
    

    エスケープの無効化

    th:text は Rails の ERB における <%= %> に相当します。エスケープせずに出力するためには <%== %> に相当する th:utext を利用します。セキュリティ上の観点から、通常は th:text でエスケープします。

    messages.properties

    hello.sub=Hello <b>world</b> default
    

    greeting.html

    <p th:utext="#{hello.sub}" />
    

    th:text 内で利用できる記法

    文字列、数値、変数の結合

    <p th:text="'Hello ' + ${name}" + 123 />
    

    文字列への変数の埋め込み

    <p th:text="|Hello ${name}|" />
    

    数値計算

    <p th:text="'1 + 1 = ' + (1 + 1)" />
    

    真偽値

    <p th:text="!true" />
    <p th:text="true and false" />
    <p th:text="1 gt 1" />
    

    条件分岐 (><使用されるべきでないため、gt (>), lt (<), ge (>=), le (<=) を利用します。)

    <p th:text="(2 gt 1) ? 'mystr'" />
    <p th:text="(1 gt 1) ? 'mystr' : 'elsestr'" />
    

    Getter の利用

    <p th:text="${user.name}" />
    <p th:text="${user.getName()}" />
    
    public class User {
        private String name;
        public void setName(String name) {
            this.name = name;
        }
        public String getName() {
            return name;
        }
    }
    
    User user = new User();
    user.setName("user name");
    model.addAttribute("user", user);
    

    文字列操作

    <p th:text="${#strings.length('aaa')}" />
    <p th:text="${#strings.toUpperCase('aaa')}" />
    

    その他の特殊変数

    <p th:text="${#vars}" />
    <p th:text="${#locale}" />
    

    オブジェクト選択

    th:object でオブジェクトを選択することで、ブロック内部で略記 (*{} または #object.) できます。

    <div th:object="${user}">
      <p th:text="*{name}" />
      <p th:text="${#object.name}" />
    </div>
    

    リンクの生成

    GreetingController.java

    model.addAttribute("url", "https://www.qoosky.io");
    model.addAttribute("query", "spring boot");
    model.addAttribute("uuid", "2496c58738");
    

    greeting.html

    <a th:href="@{https://www.qoosky.io/search(q=${query})}">qoosky search</a>
    <a th:href="@{https://www.qoosky.io/path/{uuid}(uuid=${uuid})}">qoosky Thymeleaf</a>
    <a th:href="@{${url} + '/path/{uuid}'(uuid=${uuid})}">qoosky Thymeleaf</a>
    

    一時変数の利用

    th:with を利用して、ブロック内で有効な一時変数を定義できます。

    model.addAttribute("count", 123);
    
    <div th:with="isEven=${count % 2 == 0}">
      <p th:text="${isEven} ? 'even' : 'odd'" />
    </div>
    

    条件が満たされれば表示

    <p th:if="false">本タグは表示されません。</p>
    <p th:unless="true">本タグは表示されません。</p>
    

    条件分岐

    <div th:switch="1 + 1">
      <p th:case="0">zero</p>
      <p th:case="1">one</p>
      <p th:case="*">default</p>
    </div>
    

    繰り返し処理

    GreetingController.java (参考: Java コレクション)

    List<String> names = Arrays.asList("aaa", "bbb");
    model.addAttribute("names", names);
    

    greeting.html

    <div th:each="name : ${names}">
      <p th:text="${name}" />
    </div>
    

    以下のような記述も可能です。

    <div>
      <p th:each="name : ${names}" th:text="${name}" />
    </div>
    

    繰り返しにおける状態の取得

    Stat を末尾に付与した変数名のオブジェクトで、繰り返しにおける状態を取得できます。

    <div th:each="name : ${names}">
      <p th:text="${name}" /><!-- 値 -->
      <p th:text="${nameStat.index}" /><!-- 0..size-1 -->
      <p th:text="${nameStat.count}" /><!-- 1..size -->
      <p th:text="${nameStat.size}" /><!-- ループによらず一定 -->
      <p th:text="${nameStat.current}" /><!-- ${name} と同じ意味 -->
      <p th:text="${nameStat.even}" /><!-- index が偶数 -->
      <p th:text="${nameStat.odd}" /><!-- index が奇数 -->
      <p th:text="${nameStat.first}" /><!-- 最初 -->
      <p th:text="${nameStat.last}" /><!-- 最後 -->
    </div>
    

    th:each とは直接関係ありませんが、#lists の使い方も把握しておきます。

    <p th:text="${#lists.size(names)}" />
    <p th:text="${not #lists.isEmpty(names)}" />
    

    HTML 属性値の設定

    th:attr を利用して HTML 属性値を設定できます。

    <img src="/path/to/image1.png" th:attr="src=@{/images/image2.png},alt='logo'" />
    

    実際には th:attr を利用せずに、属性に応じた th:xxx を利用します。

    <img src="/path/to/image1.png" th:src="@{/images/image2.png}" th:alt="'logo'" />
    

    その他にも、a タグの th:href や input タグの th:value などがあります。後述の th:class もよく利用します。

    CSS クラス

    th:class を利用して、HTML における class 属性を設定できます。

    <div th:each="name : ${names}" th:class="${nameStat.odd} ? 'odd-class'">
      <p th:text="${name}" />
    </div>
    

    th:classappend を利用すると、上書きではなく追加できます。

    <div th:each="name : ${names}" class="row" th:classappend="${nameStat.odd} ? 'odd-class'">
      <p th:text="${name}" />
    </div>
    

    部分テンプレート

    Rails の 部分テンプレートに相当する機能が Thymeleaf でも利用できます。th:fragment で部分テンプレートを定義して、th:replace (旧称 th:substituteby) または th:include で取り込みます。Thymeleaf 3.0 において、th:include非推奨th:insert を使うことが推奨されています。しかしながら、Spring Boot は 2017/05/30 現在において、既定では Thymeleaf 2.1 を利用するため、th:insert を利用できません。本ページでも th:include を利用します。

    src/main/resources/templates/fragments/footer.html

    <!DOCTYPE HTML>
    <html xmlns:th="http://www.thymeleaf.org">
    <body>
    <footer th:fragment="copy">
      &copy; 2017 Qoosky
    </footer>
    </body>
    </html>
    

    src/main/resources/templates/greeting.html

    th:replace

    <div th:replace="fragments/footer :: copy"></div>
    ↓
    <footer>
      &copy; 2017 Qoosky
    </footer>
    

    th:include

    <div th:include="fragments/footer :: copy"></div>
    ↓
    <div>
      &copy; 2017 Qoosky
    </div>
    

    同じファイル内の fragment を参照

    以下の例では copy が三回表示されます。二回ではないことに注意します。

    <footer th:fragment="copy">
      &copy; 2017 Qoosky
    </footer>
    
    <div th:replace="::copy"></div>
    <div th:replace="this::copy"></div>
    

    CSS セレクタの利用

    th:fragment を利用していないファイルから、CSS セレクタを利用して取り込むこともできます。

    src/main/resources/templates/fragments/footer.html

    <!DOCTYPE HTML>
    <html xmlns:th="http://www.thymeleaf.org">
    <body>
    
    <footer id="myid">
      &copy; 2017 Qoosky2
    </footer>
    
    <footer class="myclass">
      &copy; 2017 Qoosky3
    </footer>
    
    </body>
    </html>
    

    src/main/resources/templates/greeting.html

    <div th:replace="fragments/footer :: #myid"></div>
    <div th:replace="fragments/footer :: footer.myclass"></div>
    

    テンプレートへの値渡し

    footer.html

    <footer th:fragment="copy(arg1,arg2)">
      &copy; <span th:text="${arg1} + '-' + ${arg2}"></span>
    </footer>
    

    greeting.html

    <div th:replace="fragments/footer :: copy('aaa', 'bbb')"></div>
    <div th:replace="fragments/footer :: copy(arg1='aaa', arg2='bbb')"></div>
    

    引数のバリデーション th:assert も可能です。カンマ , 区切りの式のいずれかが偽であればバリデーションに失敗します。

    <footer th:fragment="copy(arg1,arg2)" th:assert="${arg1},${!#strings.isEmpty(arg2)}">
      &copy; <span th:text="${arg1} + '-' + ${arg2}"></span>
    </footer>
    

    要素の削除

    th:remove で all を指定すると、タグおよびタグ内の要素がすべて削除されます。none を指定すると何もしません。その他にタグ内の要素だけを削除する body や、タグだけを削除してタグ内の要素を削除しない tag 等があります。

    <div th:remove="true ? all : none">
      <span>my text</span>
    </div>
    

    コメントアウト

    <!--/*--><!--*/--> で囲まれた部分は Thymeleaf によってコメントとして扱われます。空白を含めて <!-- /* --> などとするとコメントとして扱われないことに注意します。

    <!--/*-->
    <span>my text</span>
    <!--*/-->
    

    JavaScript への値渡し

    <script th:inline="javascript">
      var username = [[${name}]];
      console.log(username);
    </script>
    

    Java システムプロパティの値を取得

    @environment を利用して、Java システムプロパティの値を利用できます。

    <p th:text="${@environment.getProperty('file.encoding', 'default value')}" />
    

    レイアウト

    Thymeleaf 3.0 以降

    上述のとおり、Spring Boot は 2017/05/30 現在において、既定では Thymeleaf 2.1 を利用します。Thymeleaf 3.0 で追加された一部の機能を利用したい場合は、以下のように build.gradle を設定します。最新版をこちらで検索して指定します。

    ext['thymeleaf.version'] = '3.0.2.RELEASE'
    ext['thymeleaf-layout-dialect.version'] = '2.1.1'
    
    apply plugin: 'java'
    apply plugin: 'eclipse'
    apply plugin: 'idea'
    apply plugin: 'org.springframework.boot'
    ...
    

    Thymeleaf 3.0 では、以下のような柔軟なレイアウト記法が可能になります。th:fragment で head タグをフラグメントとして定義します。引数によって、title タグの変更および link タグの追加を行います。::title および ::link は前述のとおり、同じファイル内の参照です。今回は特に CSS セレクタによる参照です。

    src/main/resources/templates/layouts/common_header.html

    <!DOCTYPE HTML>
    <html xmlns:th="http://www.thymeleaf.org">
    <head th:fragment="common_header(title, links)">
    
      <title th:replace="${title}">default title</title>
    
      <!-- 共通要素 -->
      <link rel="stylesheet" th:href="@{/css/awesomeapp.css}">
      <script type="text/javascript" th:src="@{/js/awesomeapp.js}"></script>
    
      <!-- 個別要素 -->
      <th:block th:replace="${links}">
    
    </head>
    </html>
    

    src/main/resources/templates/greeting.html

    <!DOCTYPE HTML>
    <html xmlns:th="http://www.thymeleaf.org">
    
    <head th:replace="layouts/common_header :: common_header(~{::title}, ~{::link})">
      <title>top page</title>
      <link rel="stylesheet" th:href="@{/css/bootstrap.min.css}">
      <link rel="stylesheet" th:href="@{/themes/smoothness/jquery-ui.css}">
    </head>
    
    <body>
    </body>
    </html>
    

    既定のタイトルを利用したい場合

    <head th:replace="layouts/common_header :: common_header(_, ~{::link})">
      <link rel="stylesheet" th:href="@{/css/bootstrap.min.css}">
      <link rel="stylesheet" th:href="@{/themes/smoothness/jquery-ui.css}">
    </head>
    

    追加 link を指定しない場合

    <head th:replace="layouts/common_header :: common_header(~{::title}, _)">
      <title>top page</title>
    </head>
    

    Thymeleaf Layout Dialect を利用する方法 (Thymeleaf 2 でも利用可)

    thymeleaf-layout-dialectlayout:decorate (or layout:decorator) を利用することによっても柔軟なレイアウト設定が可能になります。Sprint Boot 1.x であれば spring-boot-starter-thymeleaf の依存先として導入されるため、build.gradle に設定を追加することなく Thymeleaf Layout Dialect の機能を利用できます。TemplateEngine の設定も不要です。

    The layout dialect is already included as part of the Thymeleaf starter pack in Spring Boot 1.x, but has been removed in Spring Boot 2, hence the additional config step for Spring Boot 2 users above.
    https://ultraq.github.io/thymeleaf-layout-dialect/Installation.html

    Thymeleaf 2.x には thymeleaf-layout-dialect 1.x が対応します。Thymeleaf 3.x には thymeleaf-layout-dialect 2.x が対応します。

    $ ./gradlew dependencies
    +--- org.springframework.boot:spring-boot-starter-thymeleaf: -> 1.5.3.RELEASE
         +--- org.thymeleaf:thymeleaf-spring4:2.1.5.RELEASE
         \--- nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect:1.4.0
              \--- org.thymeleaf:thymeleaf:2.1.4.RELEASE -> 2.1.5.RELEASE (*)
    

    上述のとおり、Spring Boot は 2017/05/30 現在において、既定では Thymeleaf 2.1 を利用します。Thymeleaf 3 を利用したい場合は build.gradle で Thymeleaf 3 と thymeleaf-layout-dialect 2 を利用するように設定します。

    ext['thymeleaf.version'] = '3.0.2.RELEASE'
    ext['thymeleaf-layout-dialect.version'] = '2.1.1'
    

    thymeleaf-layout-dialect それぞれのバージョンのドキュメントは以下のとおりです。特に注意すべき差異は、2.x の layout:decorator と 3.x の layout:decorate で英単語が異なることです。

    サンプルコード

    xmlns:th="http://www.thymeleaf.org" および xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" は IDE の警告表示を回避するための設定です。<head> タグ内の要素はマージされます。例えば以下の例では <script> は最終結果に二つ含まれます。<body> タグ内の要素は layout.html が利用されます。layout:fragment の部分だけが置換されます。

    src/main/resources/templates/common/layout.html

    <!DOCTYPE html>
    <html xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout">
    <head>
      <!-- <title>My Common Title</title> -->  ←2.x
      <title layout:title-pattern="$LAYOUT_TITLE - $CONTENT_TITLE">My Common Title</title>  ←3.x
      <script src="common-script.js"></script>
    </head>
    <body>
      <div class="container">
    
        <div>Common Header</div>
    
        <div layout:fragment="content"></div>
    
        <div>
          <p>Common Footer</p>
          <p layout:fragment="content-footer">content footer here</p>
        </div>
      </div>
    </body>
    </html>
    

    src/main/resources/templates/greeting.html

    <!DOCTYPE html>
    <!-- <html xmlns:th="http://www.thymeleaf.org" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" layout:decorator="common/layout"> -->
      ↑2.x
    <html xmlns:th="http://www.thymeleaf.org" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" layout:decorate="~{common/layout}">
      ↑3.x
    <head>
      <title>My Content Title</title>
      <script src="content-script.js"></script>
    </head>
    <body>
      <div layout:fragment="content">
        <p th:text="'Hello, ' + ${name} + '!'" />
      </div>
      <p layout:fragment="content-footer">content-footer</p>
    </body>
    </html>
    
    Likeボタン(off)0
    詳細設定を開く/閉じる
    アカウント プロフィール画像

    Spring Bootでの実用的な機能をわかりやすく解説中

    記事の執筆者にステッカーを贈る

    有益な情報に対するお礼として、またはコメント欄における質問への返答に対するお礼として、 記事の読者は、執筆者に有料のステッカーを贈ることができます。

    >>さらに詳しくステッカーを贈る
    ステッカーを贈る コンセプト画像

    Feedbacks

    Feedbacks コンセプト画像

      ログインするとコメントを投稿できます。

      ログインする

      関連記事

      • Spring Security フォームログインのサンプルコード
        Spring フレームワークによる Web アプリケーション開発で、ログイン処理を実装する際は Spring Security が便利です。ここでは特に Spring Boot で Web アプリケーションを開発する場合を対象とし、フォームによる ID/Password ログインを行うためのサンプルコードをまとめます。 公式ドキュメント [Spring Security チュートリアル](http...
        えびちゃんえびちゃん11/4/2019に更新
        いいねアイコン画像0
      • Java配列の宣言方法 (C/C++との違い)
        Javaの配列 Javaの配列宣言方法はC/C++と似ているようで若干異なる。 初期化しない場合 C/C++の int array[10]; はJavaでは int array[] = new int[10]; となる。同様にC/C++の int array[3][3]; はJavaでは int array[][] = new int[3][3]; となる。 初期化
        てんとうむしてんとうむし4/13/2018に更新
        いいねアイコン画像0
      • PlantUML による UML 図の描き方
        サムネイル画像-c788fffde5
        PlantUML はテキスト形式で表現されたシーケンス図やクラス図といった UML (Unified Modeling Language) 図の情報から画像を生成するためのツールです。簡単な使い方をまとめます。 インストール方法の選択 Atom や Eclipse のプラグインをインストールしてエディタから利用する方法、JAR をダウンロードして Java コマンドで実行する方法、Redmine ...
        kentakenta12/21/2019に更新
        いいねアイコン画像0
      • Akka HTTP サンプルコード (Scala)
        サムネイル画像-a98142497c
        Akka アクターを用いて実装された汎用 HTTP フレームワークです。Spray の後継です。コアモジュールである akka-http-core は 2016/2/17 に experimental が外れました。akka-http などのいくつかのサブモジュールは 2016/3/1 現在 experimental のままですが、基本的な
        雄太雄太9/7/2021に更新
        いいねアイコン画像0
      • Kestrel の使用例
        Kestrel は Message Queue (MQ) の実装のひとつです。一般に MQ はアプリケーション間やプロセス間、スレッド間で非同期に通信するために用いられます。メッセージの送信側は MQ に書き込めば受信側の応答を待たずに次の処理に非同期に進むことができます。Kestrel はわずか 2500 行程の Scala で実装されており JVM で動作します。MQ 自体はメモリ上に存在する...
        したくんしたくん9/12/2017に更新
        いいねアイコン画像0