From 6b5b42c4192518e07d4e80f8784cdbbf53dc8903 Mon Sep 17 00:00:00 2001 From: x ronger Date: Mon, 18 Nov 2019 19:39:37 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E8=B7=AF=E5=BE=84=E5=8F=98?= =?UTF-8?q?=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../web/api/article/ArticleController.java | 36 +++---------------- .../web/api/common/CommonApiController.java | 32 +++++++++++++++++ 2 files changed, 36 insertions(+), 32 deletions(-) diff --git a/src/main/java/com/rymcu/vertical/web/api/article/ArticleController.java b/src/main/java/com/rymcu/vertical/web/api/article/ArticleController.java index 2c16440..6cfc78d 100644 --- a/src/main/java/com/rymcu/vertical/web/api/article/ArticleController.java +++ b/src/main/java/com/rymcu/vertical/web/api/article/ArticleController.java @@ -1,20 +1,15 @@ package com.rymcu.vertical.web.api.article; -import com.github.pagehelper.PageHelper; -import com.github.pagehelper.PageInfo; -import com.rymcu.vertical.core.mapper.Mapper; import com.rymcu.vertical.core.result.GlobalResult; import com.rymcu.vertical.core.result.GlobalResultGenerator; -import com.rymcu.vertical.dto.ArticleDTO; -import com.rymcu.vertical.entity.Article; -import com.rymcu.vertical.jwt.def.JwtConstants; import com.rymcu.vertical.service.ArticleService; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; -import java.util.HashMap; -import java.util.List; import java.util.Map; @RestController @@ -24,21 +19,6 @@ public class ArticleController { @Resource private ArticleService articleService; - @GetMapping("/articles") - public GlobalResult articles(@RequestParam(defaultValue = "0") Integer page,@RequestParam(defaultValue = "10") Integer rows,@RequestParam(defaultValue = "") String searchText,@RequestParam(defaultValue = "") String tag){ - PageHelper.startPage(page, rows); - List list = articleService.articles(searchText,tag); - PageInfo pageInfo = new PageInfo(list); - Map map = new HashMap(); - map.put("articles", pageInfo.getList()); - Map pagination = new HashMap(); - pagination.put("paginationPageCount",pageInfo.getPages()); - pagination.put("paginationPageNums",pageInfo.getNavigatepageNums()); - pagination.put("currentPage",pageInfo.getPageNum()); - map.put("pagination", pagination); - return GlobalResultGenerator.genSuccessResult(map); - } - @PostMapping("/post") public GlobalResult postArticle(@RequestParam(name = "idArticle",defaultValue = "0") Integer idArticle,@RequestParam(name = "articleTitle",defaultValue = "") String articleTitle, @RequestParam(name = "articleContent",defaultValue = "") String articleContent,@RequestParam(name = "articleContentHtml",defaultValue = "") String articleContentHtml, @@ -47,12 +27,4 @@ public class ArticleController { return GlobalResultGenerator.genSuccessResult(map); } - @GetMapping("/detail/{id}") - public GlobalResult detail(@PathVariable Integer id){ - ArticleDTO articleDTO = articleService.findArticleDTOById(id); - Map map = new HashMap<>(); - map.put("article", articleDTO); - return GlobalResultGenerator.genSuccessResult(map); - } - } diff --git a/src/main/java/com/rymcu/vertical/web/api/common/CommonApiController.java b/src/main/java/com/rymcu/vertical/web/api/common/CommonApiController.java index 88c10a5..866981e 100644 --- a/src/main/java/com/rymcu/vertical/web/api/common/CommonApiController.java +++ b/src/main/java/com/rymcu/vertical/web/api/common/CommonApiController.java @@ -1,10 +1,14 @@ package com.rymcu.vertical.web.api.common; +import com.github.pagehelper.PageHelper; +import com.github.pagehelper.PageInfo; import com.rymcu.vertical.core.exception.ServiceException; import com.rymcu.vertical.core.result.GlobalResult; import com.rymcu.vertical.core.result.GlobalResultGenerator; import com.rymcu.vertical.core.result.GlobalResultMessage; +import com.rymcu.vertical.dto.ArticleDTO; import com.rymcu.vertical.entity.User; +import com.rymcu.vertical.service.ArticleService; import com.rymcu.vertical.service.JavaMailService; import com.rymcu.vertical.service.UserService; import io.swagger.annotations.ApiOperation; @@ -12,6 +16,7 @@ import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import java.util.HashMap; +import java.util.List; import java.util.Map; @RestController @@ -22,6 +27,8 @@ public class CommonApiController { private JavaMailService javaMailService; @Resource private UserService userService; + @Resource + private ArticleService articleService; @ApiOperation(value = "获取邮件验证码") @PostMapping("/get-email-code") @@ -56,4 +63,29 @@ public class CommonApiController { public GlobalResult heartbeat(){ return GlobalResultGenerator.genSuccessResult("heartbeat"); } + + @GetMapping("/articles") + public GlobalResult articles(@RequestParam(defaultValue = "0") Integer page,@RequestParam(defaultValue = "10") Integer rows,@RequestParam(defaultValue = "") String searchText,@RequestParam(defaultValue = "") String tag){ + PageHelper.startPage(page, rows); + List list = articleService.articles(searchText,tag); + PageInfo pageInfo = new PageInfo(list); + Map map = new HashMap(); + map.put("articles", pageInfo.getList()); + Map pagination = new HashMap(); + pagination.put("paginationPageCount",pageInfo.getPages()); + pagination.put("paginationPageNums",pageInfo.getNavigatepageNums()); + pagination.put("currentPage",pageInfo.getPageNum()); + map.put("pagination", pagination); + return GlobalResultGenerator.genSuccessResult(map); + } + + + + @GetMapping("/articles/{id}") + public GlobalResult detail(@PathVariable Integer id){ + ArticleDTO articleDTO = articleService.findArticleDTOById(id); + Map map = new HashMap<>(); + map.put("article", articleDTO); + return GlobalResultGenerator.genSuccessResult(map); + } }