GithubHelp home page GithubHelp logo

sofiangrh / blade Goto Github PK

View Code? Open in Web Editor NEW

This project forked from lets-blade/blade

0.0 2.0 0.0 4.94 MB

:rocket: a simple, elegant Java Web Framework!

Home Page: http://bladejava.com/

Java 100.00%

blade's Introduction

Build Status maven-central License @biezhi on weibo

中文说明

What Is Blade?

Blade is a lightweight MVC framework. It is based on the principles of simplicity and elegance. If you like it, can be Star and Fork, thanks!

Features

  • Lightweight. The code is simple and structure is clear
  • Modular (you can choose which components to use)
  • Support plug-in extension mechanism
  • Restful style routing interface
  • Multiple configuration files support (currently properties, json and coding)
  • Eembed jetty server and template engine support
  • Support jdk1.6 or higher version

Overview

  • Simplicity. The design is simple, easy to understand and doesn't introduce many layers between you and the standard library. It is a goal of the project that users should be able to understand the whole framework in a single day.
  • Elegance. blade Support the REST style routing interface, provide DSL grammar to write, no invasive interceptors.

Get Start

To get started, first include the Blade library :

Maven config:

<dependency>
	<groupId>com.bladejava</groupId>
	<artifactId>blade-core</artifactId>
	<version>last_version</version>
</dependency>

create Main method like this:

public class App {
	
	public static void main(String[] args) {
		Blade blade = Blade.me();
		blade.get("/", (request, response) -> {
			response.html("<h1>Hello blade!</h1>");
		});
		blade.listen(9001).start();
	}
}

Run it and point your browser to http://localhost:9001. There you go, you've just created your first Blade app!

API Example

public static void main(String[] args) {
	Blade blade = Blade.me();
	blade.get("/user/21", getxxx);
	blade.post("/save", postxxx);
	blade.delete("/del/21", deletexxx);
	blade.put("/put", putxxx);
	blade.listen(9001).start();
}

REST URL Parameters

public static void main(String[] args) {
	Blade blade = Blade.me();
	blade.get("/user/:uid", (request, response) -> {
		Integer uid = request.paramAsInt("uid");
		response.text("uid : " + uid);
	});
	
	blade.get("/users/:uid/post/:pid", (request, response) -> {
		Integer uid = request.paramAsInt("uid");
		Integer pid = request.paramAsInt("pid");
		String msg = "uid = " + uid + ", pid = " + pid;
		response.text(msg);
	});
	
	blade.listen(9001).start();
}

Form URL Parameters

public static void main(String[] args) {
	Blade blade = Blade.me();
	blade.get("/user", (request, response) -> {
		Integer uid = request.query("uid");
		response.text("uid : " + uid);
	});
	blade.listen(9001).start();
}

Upload File

public void upload_img(Request request, Response response){
		
	JsonObject jsonObject = new JsonObject();

	FileItem[] fileItems = request.files();
	if(null != fileItems && fileItems.length > 0){
		
		FileItem fileItem = fileItems[0];
		File file = fileItem.getFile();

		String fileRealPath = "your upload file path!";
		
		nioTransferCopy(file, fileRealPath);
	}
}

Route Config File

route.conf

GET		/					IndexRoute.home
GET		/signin				IndexRoute.show_signin
POST	/signin				IndexRoute.signin
GET		/signout			IndexRoute.signout
POST	/upload_img			UploadRoute.upload_img

Route Intercept

public static void main(String[] args) {
	Blade blade = Blade.me();
	blade.before("/.*", (request, response) -> {
		System.out.println("before...");
	});
	blade.listen(9001).start();
}

DSL DB Operation

// save
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;
}

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

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

OK, all this may seem simple, refer to the guidelines for use more ready-made examples for your reference:

Plan

    1. The development of social application platform
    1. Add the test code
    1. Optimize the code base
    1. Optimization of concurrent ability

Update

update log

Contact

licenses

Copyright 2015 biezhi

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

blade's People

Contributors

hellokaton avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.