本文整理了Java中spark.Spark.after()
方法的一些代码示例,展示了Spark.after()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Spark.after()
方法的具体详情如下:
包路径:spark.Spark
类名称:Spark
方法名:after
[英]Maps one or many filters to be executed after any matching routes
[中]映射一个或多个过滤器,以便在任何匹配路由之后执行
代码示例来源:origin: cbilgili/zemberek-nlp-server
public BaseController(final Gson jsonConverter) {
this.jsonConverter = jsonConverter;
// -- Check the authentication
// before((req, res) -> {
// validateLogin(jsonConverter, req);
// });
// -- Set proper content-type to all responses
after((req, res) -> {
res.type("application/json;charset=UTF-8");
});
// -- Handle the exceptions
handleExceptions(jsonConverter);
}
代码示例来源:origin: GoogleCloudPlatform/java-docs-samples
/**
* Creates a controller that maps requests to actions.
*/
public UserController(final UserService userService) {
Spark.staticFileLocation("/public");
get("/api/users", (req, res) -> userService.getAllUsers(), json());
get("/api/users/:id", (req, res) -> userService.getUser(req.params(":id")), json());
post("/api/users",
(req, res) -> userService.createUser(req.queryParams("name"), req.queryParams("email")),
json());
put("/api/users/:id", (req, res) -> userService.updateUser(
req.params(":id"),
req.queryParams("name"),
req.queryParams("email")
), json());
delete("/api/users/:id", (req, res) -> userService.deleteUser(req.params(":id")), json());
after((req, res) -> {
res.type("application/json");
});
exception(IllegalArgumentException.class, (error, req, res) -> {
res.status(400);
res.body(toJson(new ResponseError(error)));
});
}
代码示例来源:origin: yeriomin/token-dispenser
res.header("Access-Control-Request-Method", "GET");
});
after((req, res) -> res.type("text/plain"));
Server.passwords = PasswordsDbFactory.get(config);
get("/token/email/:email", (req, res) -> new TokenResource().handle(req, res));
代码示例来源:origin: vanillasource/jaywire
public void addRoutes() {
Spark.before((request, response) -> {
getServletRequestScope().setStorage(request.raw());
getHttpSessionScope().setStorage(request.session(true).raw());
});
Spark.after((request, response) -> {
getServletRequestScope().clearStorage();
getHttpSessionScope().clearStorage();
});
}
}
代码示例来源:origin: tipsy/spark-basic-structure
public static void main(String[] args) {
// Instantiate your dependencies
bookDao = new BookDao();
userDao = new UserDao();
// Configure Spark
port(4567);
staticFiles.location("/public");
staticFiles.expireTime(600L);
enableDebugScreen();
// Set up before-filters (called before each get/post)
before("*", Filters.addTrailingSlashes);
before("*", Filters.handleLocaleChange);
// Set up routes
get(Path.Web.INDEX, IndexController.serveIndexPage);
get(Path.Web.BOOKS, BookController.fetchAllBooks);
get(Path.Web.ONE_BOOK, BookController.fetchOneBook);
get(Path.Web.LOGIN, LoginController.serveLoginPage);
post(Path.Web.LOGIN, LoginController.handleLoginPost);
post(Path.Web.LOGOUT, LoginController.handleLogoutPost);
get("*", ViewUtil.notFound);
//Set up after-filters (called after each get/post)
after("*", Filters.addGzipHeader);
}
代码示例来源:origin: tipsy/spark-basic-structure
public static void main(String[] args) {
// Instantiate your dependencies
bookDao = new BookDao();
userDao = new UserDao();
// Configure Spark
port(4567);
staticFiles.location("/public");
staticFiles.expireTime(600L);
enableDebugScreen();
// Set up before-filters (called before each get/post)
before("*", Filters.addTrailingSlashes);
before("*", Filters.handleLocaleChange);
// Set up routes
get(Path.Web.INDEX, IndexController.serveIndexPage);
get(Path.Web.BOOKS, BookController.fetchAllBooks);
get(Path.Web.ONE_BOOK, BookController.fetchOneBook);
get(Path.Web.LOGIN, LoginController.serveLoginPage);
post(Path.Web.LOGIN, LoginController.handleLoginPost);
post(Path.Web.LOGOUT, LoginController.handleLogoutPost);
get("*", ViewUtil.notFound);
//Set up after-filters (called after each get/post)
after("*", Filters.addGzipHeader);
}
代码示例来源:origin: ikidou/Retrofit2Demo
Spark.after(new Filter() {
@Override
public void handle(Request request, Response response) throws Exception {
内容来源于网络,如有侵权,请联系作者删除!