代码拉取完成,页面将自动刷新
注意 : 这里的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.
Java8 + Maven3.3
<dependency>
<groupId>cc.liloo</groupId>
<artifactId>spark-mini</artifactId>
<version>${version}</version>
</dependency>
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
}
});
}
/**
* 整个项目的使用方法非常简单, 只需要在控制器上实现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.";
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。