com.blade.mvc.annotation.GetRoute Java Examples
The following examples show how to use
com.blade.mvc.annotation.GetRoute.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CategoryController.java From tale with MIT License | 6 votes |
/** * 某个分类详情页分页 */ @GetRoute(value = {"category/:keyword/:page", "category/:keyword/:page.html"}) public String categories(Request request, @PathParam String keyword, @PathParam int page, @Param(defaultValue = "12") int limit) { page = page < 0 || page > TaleConst.MAX_PAGE ? 1 : page; Metas metaDto = metasService.getMeta(Types.CATEGORY, keyword); if (null == metaDto) { return this.render_404(); } Page<Contents> contentsPage = contentsService.getArticles(metaDto.getMid(), page, limit); request.attribute("articles", contentsPage); request.attribute("meta", metaDto); request.attribute("type", "分类"); request.attribute("keyword", keyword); request.attribute("is_category", true); request.attribute("page_prefix", "/category/" + keyword); return this.render("page-category"); }
Example #2
Source File: CategoryController.java From tale with MIT License | 6 votes |
/** * 标签下文章分页 */ @GetRoute(value = {"tag/:name/:page", "tag/:name/:page.html"}) public String tags(Request request, @PathParam String name, @PathParam int page, @Param(defaultValue = "12") int limit) { page = page < 0 || page > TaleConst.MAX_PAGE ? 1 : page; Metas metaDto = metasService.getMeta(Types.TAG, name); if (null == metaDto) { return this.render_404(); } Page<Contents> contentsPage = contentsService.getArticles(metaDto.getMid(), page, limit); request.attribute("articles", contentsPage); request.attribute("meta", metaDto); request.attribute("type", "标签"); request.attribute("keyword", name); request.attribute("is_tag", true); request.attribute("page_prefix", "/tag/" + name); return this.render("page-category"); }
Example #3
Source File: IndexController.java From tale with MIT License | 6 votes |
/** * 自定义页面 */ @CsrfToken(newToken = true) @GetRoute(value = {"/:cid", "/:cid.html"}) public String page(@PathParam String cid, Request request) { Optional<Contents> contentsOptional = contentsService.getContents(cid); if (!contentsOptional.isPresent()) { return this.render_404(); } Contents contents = contentsOptional.get(); if (contents.getAllowComment()) { int cp = request.queryInt("cp", 1); request.attribute("cp", cp); } request.attribute("article", contents); Contents temp = new Contents(); temp.setHits(contents.getHits() + 1); temp.update(contents.getCid()); if (Types.ARTICLE.equals(contents.getType())) { return this.render("post"); } if (Types.PAGE.equals(contents.getType())) { return this.render("page"); } return this.render_404(); }
Example #4
Source File: IndexController.java From tale with MIT License | 6 votes |
/** * feed页 * * @return */ @GetRoute(value = {"feed", "feed.xml", "atom.xml"}) public void feed(Response response) { List<Contents> articles = new Contents().where("type", Types.ARTICLE).and("status", Types.PUBLISH) .and("allow_feed", true) .findAll(OrderBy.desc("created")); try { String xml = TaleUtils.getRssXml(articles); response.contentType("text/xml; charset=utf-8"); response.body(xml); } catch (Exception e) { log.error("生成 rss 失败", e); } }
Example #5
Source File: IndexController.java From tale with MIT License | 6 votes |
/** * 文章页 */ @CsrfToken(newToken = true) @GetRoute(value = {"article/:cid", "article/:cid.html"}) public String post(Request request, @PathParam String cid) { Optional<Contents> contentsOptional = contentsService.getContents(cid); if (!contentsOptional.isPresent()) { return this.render_404(); } Contents contents = contentsOptional.get(); if (Types.DRAFT.equals(contents.getStatus())) { return this.render_404(); } request.attribute("article", contents); request.attribute("is_post", true); if (contents.getAllowComment()) { int cp = request.queryInt("cp", 1); request.attribute("cp", cp); } Contents temp = new Contents(); temp.setHits(contents.getHits() + 1); temp.update(contents.getCid()); return this.render("post"); }
Example #6
Source File: IndexController.java From tale with MIT License | 5 votes |
/** * sitemap 站点地图 * * @return */ @GetRoute(value = {"sitemap", "sitemap.xml"}) public void sitemap(Response response) { List<Contents> articles = new Contents().where("type", Types.ARTICLE).and("status", Types.PUBLISH) .and("allow_feed", true) .findAll(OrderBy.desc("created")); try { String xml = TaleUtils.getSitemapXml(articles); response.contentType("text/xml; charset=utf-8"); response.body(xml); } catch (Exception e) { log.error("生成 sitemap 失败", e); } }
Example #7
Source File: AttributesExampleController.java From tutorials with MIT License | 5 votes |
@GetRoute("/session-attribute-example") public void getSessionAttribute(Request request, Response response) { Session session = request.session(); session.attribute("session-val", SESSION_VALUE); String sessionVal = session.attribute("session-val"); response.text(sessionVal); }
Example #8
Source File: RouteExampleController.java From tutorials with MIT License | 5 votes |
@GetRoute("/load-configuration-in-a-route") public void loadConfigurationInARoute(Response response) { String authors = WebContext.blade() .env("app.authors", "Unknown authors"); log.info("[/load-configuration-in-a-route] Loading 'app.authors' from configuration, value: " + authors); response.render("index.html"); }
Example #9
Source File: IndexController.java From tale with MIT License | 5 votes |
@GetRoute(value = {"search/:keyword/:page", "search/:keyword/:page.html"}) public String search(Request request, @PathParam String keyword, @PathParam int page, @Param(defaultValue = "12") int limit) { page = page < 0 || page > TaleConst.MAX_PAGE ? 1 : page; Page<Contents> articles = new Contents().where("type", Types.ARTICLE).and("status", Types.PUBLISH) .like("title", "%" + keyword + "%").page(page, limit, "created desc"); request.attribute("articles", articles); request.attribute("type", "搜索"); request.attribute("keyword", keyword); request.attribute("page_prefix", "/search/" + keyword); return this.render("page-category"); }
Example #10
Source File: IndexController.java From tale with MIT License | 5 votes |
/** * 首页分页 * * @param request * @param page * @param limit * @return */ @GetRoute(value = {"page/:page", "page/:page.html"}) public String index(Request request, @PathParam int page, @Param(defaultValue = "12") int limit) { page = page < 0 || page > TaleConst.MAX_PAGE ? 1 : page; if (page > 1) { this.title(request, "第" + page + "页"); } request.attribute("page_num", page); request.attribute("limit", limit); request.attribute("is_home", true); request.attribute("page_prefix", "/page"); return this.render("index"); }
Example #11
Source File: IndexController.java From tale with MIT License | 4 votes |
@GetRoute(value = {"search", "search.html"}) public String search(Request request, @Param(defaultValue = "12") int limit) { String keyword = request.query("s").orElse(""); return this.search(request, keyword, 1, limit); }
Example #12
Source File: CategoryController.java From tale with MIT License | 4 votes |
/** * 某个分类详情页 */ @GetRoute(value = {"category/:keyword", "category/:keyword.html"}) public String categories(Request request, @PathParam String keyword, @Param(defaultValue = "12") int limit) { return this.categories(request, keyword, 1, limit); }
Example #13
Source File: RouteBuilderTest.java From blade with Apache License 2.0 | 4 votes |
@GetRoute public void hello(Response response) { response.text("Ok."); }
Example #14
Source File: RouteExampleController.java From tutorials with MIT License | 4 votes |
@GetRoute("/route-example") public String get() { return "get.html"; }
Example #15
Source File: RouteExampleController.java From tutorials with MIT License | 4 votes |
@GetRoute("/template-output-test") public void templateOutputTest(Request request, Response response) { request.attribute("name", "Blade"); response.render("template-output-test.html"); }
Example #16
Source File: ParameterInjectionExampleController.java From tutorials with MIT License | 4 votes |
@GetRoute("/params/form") public void formParam(@Param String name, Response response) { log.info("name: " + name); response.text(name); }
Example #17
Source File: ParameterInjectionExampleController.java From tutorials with MIT License | 4 votes |
@GetRoute("/params/path/:uid") public void restfulParam(@PathParam Integer uid, Response response) { log.info("uid: " + uid); response.text(String.valueOf(uid)); }
Example #18
Source File: ParameterInjectionExampleController.java From tutorials with MIT License | 4 votes |
@GetRoute("/params/header") public void headerParam(@HeaderParam String customheader, Response response) { log.info("Custom header: " + customheader); response.text(customheader); }
Example #19
Source File: ParameterInjectionExampleController.java From tutorials with MIT License | 4 votes |
@GetRoute("/params/cookie") public void cookieParam(@CookieParam(defaultValue = "default value") String myCookie, Response response) { log.info("myCookie: " + myCookie); response.text(myCookie); }
Example #20
Source File: AttributesExampleController.java From tutorials with MIT License | 4 votes |
@GetRoute("/request-attribute-example") public void getRequestAttribute(Request request, Response response) { request.attribute("request-val", REQUEST_VALUE); String requestVal = request.attribute("request-val"); response.text(requestVal); }
Example #21
Source File: AttributesExampleController.java From tutorials with MIT License | 4 votes |
@GetRoute("/header-example") public void getHeader(Request request, Response response) { String headerVal = request.header("a-header", HEADER); response.header("a-header", headerVal); }
Example #22
Source File: IndexController.java From tale with MIT License | 2 votes |
/** * 搜索页 * * @param keyword * @return */ @GetRoute(value = {"search/:keyword", "search/:keyword.html"}) public String search(Request request, @PathParam String keyword, @Param(defaultValue = "12") int limit) { return this.search(request, keyword, 1, limit); }
Example #23
Source File: IndexController.java From tale with MIT License | 2 votes |
/** * 首页 * * @return */ @GetRoute public String index(Request request, @Param(defaultValue = "12") int limit) { return this.index(request, 1, limit); }
Example #24
Source File: CategoryController.java From tale with MIT License | 2 votes |
/** * 标签详情页 * * @param name 标签名 */ @GetRoute(value = {"tag/:name", "tag/:name.html"}) public String tagPage(Request request, @PathParam String name, @Param(defaultValue = "12") int limit) { return this.tags(request, name, 1, limit); }