12 Star 28 Fork 4

JinYu / SparkMini

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

SparkMini

License License SparkMini

Spark - 一个基于 Java 8的小型Web框架

Spark - A tiny web framework for Java 8

注意 : 这里的Spark不是用于大数据处理的Spark, 而是一个简单的Web框架, 这里是官方Github地址.
Notice : This Spark is not used for large data processing Spark, but a simple Web framework, here is the official Github page.

这个项目是一个简单的封装, 为的是提供一种简单的REST接口启动方式.
This project is a simple wrapper, in order to provide a simple way to start the REST interface.

  • 环境要求/Environment
Java8 + Maven3.3
  • Maven
<dependency>
	<groupId>cc.liloo</groupId>
	<artifactId>spark-mini</artifactId>
	<version>${version}</version>
</dependency>
  • 怎么使用 - 启动类 / How to use - Start
public static void main(String[] args) {
	Set<Class<?>> list = RouterHandler.getRouters("package name here");
	list.stream().forEach(cls -> {
		// 反射执行 / Reflect and invoke
		try {
			Router server = (Router) cls.newInstance();
			server.getClass().getMethod("route").invoke(server);
		} catch (InstantiationException e) {
			// ignore
		} catch (NoSuchMethodException e) {
			// ignore
		} catch (SecurityException e) {
			// ignore
		} catch (IllegalArgumentException e) {
			// ignore
		} catch (InvocationTargetException e) {
			// ignore
		} catch (IllegalAccessException e) {
			// ignore
		}
	});
}
  • 怎么使用 - 控制器类 / How to use - Controllers
/**
 * 整个项目的使用方法非常简单, 只需要在控制器上实现Router类即可.
 * The use of the entire project is very simple, only need to inherit the Router class can be on the controller.
 */
public class IndexRouter implements Router {
   	@Override
   	public void route() {
		// 这里的Spark是Spark框架提供的, 相关文档请参考Sprak官网. http://sparkjava.com/documentation
		// Spark is provided by the Spark framework. Please refer to the Sprak website for documentation. http://sparkjava.com/documentation
		Spark.get("/", (request, response) -> {
   			return "Hello, this is /.";
   		});
   		Spark.path("/api", () -> {
   			Spark.get("/account", IndexController::account);
   		});
   	}
   	private static String account(Request requset, Response response) {
   		return "Hello, this is /api/account.";
   	}
}

空文件

简介

Spark - 一个基于 Java 8的小型Web框架 展开 收起
Java
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
Java
1
https://gitee.com/liloo/SparkMini.git
git@gitee.com:liloo/SparkMini.git
liloo
SparkMini
SparkMini
master

搜索帮助