微型Java Web框架:pippo
jopen
10年前
它是一个开源(Apache许可证)微型Java Web框架,拥有最少的依赖,以及快速的学习曲线。 该项目的目标是创建一个微型的Web框架在Java中这应该是易于使用和破解。
其概念是不是新的 (灵感来自于 Sinatra, Express JS, Play Framework),但目的是提供一个清晰,简单易用的模块化解决方案。 pippo可用于中小型应用,并应用在基于微服务架构的应用程序中。
Artifacts
- Pippo Core
pippo-core
(jar) - Pippo Jetty
pippo-jetty
(jar) - Pippo Freemarker
pippo-fremarker
(jar)
public class SimpleDemo { public static void main(String[] args) { // new Pippo().start(); // run the default web server with the default web server settings Pippo pippo = new Pippo(new SimpleApplication()); pippo.getServer().getSettings().staticFilesLocation("/public"); pippo.start(); } } public class SimpleApplication extends Application { @Override public void init() { super.init(); GET("/", new RouteHandler() { @Override public void handle(Request request, Response response) { response.send("Hello World"); } }); GET("/file", new RouteHandler() { @Override public void handle(Request request, Response response) { response.file(new File("pom.xml")); } }); GET("/json", new RouteHandler() { @Override public void handle(Request request, Response response) { Contact contact = new Contact() .setName("John") .setPhone("0733434435") .setAddress("Sunflower Street, No. 6"); // you can use variant 1 or 2 // response.contentType(HttpConstants.ContentType.APPLICATION_JSON); // 1 // response.send(new Gson().toJson(contact)); // 1 response.json(contact); // 2 } }); GET("/template", new RouteHandler() { @Override public void handle(Request request, Response response) { Map<String, Object> model = new HashMap<String, Object>(); model.put("greeting", "Hello my friend"); response.render("hello.ftl", model); } }); GET("/error", new RouteHandler() { @Override public void handle(Request request, Response response) { throw new RuntimeException("Errorrrrrrrr..."); } }); } }