A lightweight java-web framework,reference from simplify_mvc and javalin, just use for learning exchange ,I trust that you wont to use for production environment hah hah
一款轻量级java-web框架,参考自SpringMVC与Javalin,仅作学习交流使用
Updated Continually
- Lifecycle AOP
- file response support
- any more...
- 😎 Simplify
- 😍 OOTB
- 🚀 Get started quickly
- 📕 Can be used for learning
- ✌️ Less code amount
- 🦾 Also no @Annotation
- ❤️ Also no reflection
- 😀 Just function
You just need call some functions , so easy
import this by maven
, gradle
, or move it to your lib-dir
This example to build and run a simple web application
public class Main {
public static void main(String[] args) {
Bendoroll app = Bendoroll.create();
app.get("/example",ctx->{
ctx.html("Hello World!");
});
app.start();
}
}
There exist some examples about how to use the framework
public class Main {
public static void main(String[] args) {
Bendoroll app = Bendoroll.create(8080);
app.get("/user", ctx -> {
ctx.ok.put(new User("ZJamss","Dont have delusion"));
});
app.post("/user", ctx -> {
final User user = ctx.body(User.class);
//.... do something in Dao
ctx.ok();
});
app.put("/user", ctx -> {
final User user = ctx.body(User.class);
//.... do something in Dao
ctx.ok();
});
app.delete("/user", ctx -> {
final User user = ctx.body(User.class);
//.... do something in Dao
ctx.ok();
});
app.start();
}
static class User{}
}
public class Main {
public static void main(String[] args) {
Bendoroll app = Bendoroll.create(8080);
app.post("/user", ctx -> {
final User user = ctx.body(User.class);
//.... do something in Dao
if(user == null){
throw new RuntimeException("cant resolve the request body");
}
ctx.ok();
});
app.exception(RuntimeException.class,((e, ctx) -> {
//do something to process the exception, such as log...
ctx.error(400);
}));
app.start();
}
static class User{}
}
public class Main {
public static void main(String[] args) {
Bendoroll app = Bendoroll.create();
app.get("/", ctx -> {
ctx.ok().put("person", new Person(ctx.param("name"), 19, "Dont have delusion"));
});
app.aspect(Lifecycle.AROUND, "/", ctx -> {
ctx.ok().put("around","around");
return true;
});
app.aspect(Lifecycle.BEFORE, "/", ctx -> {
ctx.ok().put("before","before");
if(ctx.param("name") == null){
ctx.error(400,"别来沾边");
}
return false;
});
app.aspect(Lifecycle.AFTER, "/", ctx -> {
ctx.ok().put("after","after");
return true;
});
app.aspect(Lifecycle.EXCEPTION, "/", ctx -> {
ctx.ok().put("exception","exception");
return true;
});
app.exception(BaseException.class, (e, ctx) -> {
ctx.html("error");
});
app.start();
}
static class Person {}
}
public class Main {
public static void main(String[] args) {
Bendoroll app = Bendorollmo
.create()
.fileAccess(true) //Default Off
.fileFolderName("static"); //Default `resources/public`
app.get("/index",ctx -> {
ctx.file("index.html");
});
//or access host:port/filename to view it online
//for example localhost:8080/index.html
app.start();
}
}