com.firefly.example.http.hello.TemplateDemo Maven / Gradle / Ivy
package com.firefly.example.http.hello;
import com.firefly.$;
import com.firefly.codec.http2.model.HttpHeader;
import java.util.Arrays;
import java.util.List;
/**
* @author Pengtao Qiu
*/
public class TemplateDemo {
public static class Example {
List- items() {
return Arrays.asList(
new Item("Item 1", "$19.99", Arrays.asList(new Feature("New!"), new Feature("Awesome!"))),
new Item("Item 2", "$29.99", Arrays.asList(new Feature("Old."), new Feature("Ugly.")))
);
}
static class Item {
Item(String name, String price, List
features) {
this.name = name;
this.price = price;
this.features = features;
}
String name, price;
List features;
}
static class Feature {
Feature(String description) {
this.description = description;
}
String description;
}
}
public static void main(String[] args) {
$.httpServer().router().get("/example")
.handler(ctx -> ctx.put(HttpHeader.CONTENT_TYPE, "text/plain")
.renderTemplate("template/hello/example.mustache", new Example()))
.listen("localhost", 8080);
}
}