Blade - 一款简洁优雅的 Java Web 框架

·  阅读 4164
Blade - 一款简洁优雅的 Java Web 框架

新一代JavaWeb框架,不依赖更多的库,摆脱SSH的臃肿,模块化设计,使用起来更轻便!

代码简洁、结构清晰,不足100KB源代码,写更少的代码快速开发!

支持用户基于Blade扩展其他功能,如redis,dbutils等集成,现已扩展了众多模版引擎和Sql2o组件~

最简示例


public class App {
    
    public static void main(String[] args) {
        Blade blade = Blade.me();
        
        blade.get("/", new RouteHandler() {
            public void handle(Request request, Response response) {
                response.html("

Hello Blade!

"); } }); blade.start(); } }

极简路由


blade.route("/hello", NormalSample.class, "hello");
blade.route("/save_user", NormalSample.class, "post:saveUser");


public class NormalSample {
    
    public void hello(Request request, Response response){
        System.out.println("进入hello~");
        request.attribute("name", "rose baby");
        response.render("hi");
    }
    
    public void saveUser(Request request, Response response){
        System.out.println("进入saveUser~");
        
    }
}

爬虫能力


public class Soup {
    
    private int start_page = 1,end_page = 100;
    private static final String REG = 
        "
([\\s\\S]*?)

([\\s\\S]*?)

([\\s\\S]*?)"
; private String getBody(){ return HttpRequest .get(String.format("http://soup.setin.cn/p/%d.html", start_page)) .userAgent("Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)") .body(); } public void execute(){ } public static void main(String[] args) { Soup joke = new Soup(); joke.execute(); } }

DSL数据库操作


public boolean save(Integer cid, Integer tid, Integer fuid, Integer tuid) {
    return model.insert().param("cid", cid)
    .param("tid", tid)
    .param("fuid", fuid)
    .param("tuid", tuid)
    .param("addtime", new Date())
    .param("ntype", 0).executeAndCommit() > 0;
}


public User signin(String username, String password) {
    String pwd = EncrypKit.md5(username + password);
    return model.select().eq("username", username)
    .eq("password", pwd).fetchOne();
}


public Long getUserCount(String email){
    return model.count().eq("email", email).fetchCount();
}


查看详细代码

分类:
后端
标签:
分类:
后端
标签:
收藏成功!
已添加到「」, 点击更改