ArticleController.java 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. package com.caimei.www.controller.unlimited;
  2. import com.caimei.www.controller.BaseController;
  3. import com.caimei.www.pojo.JsonModel;
  4. import com.caimei.www.pojo.page.BaseLink;
  5. import com.caimei.www.pojo.page.ImageLink;
  6. import com.caimei.www.service.ArticleService;
  7. import com.github.pagehelper.PageInfo;
  8. import org.springframework.beans.factory.annotation.Autowired;
  9. import org.springframework.stereotype.Controller;
  10. import org.springframework.ui.Model;
  11. import org.springframework.web.bind.annotation.GetMapping;
  12. import org.springframework.web.bind.annotation.PathVariable;
  13. import org.springframework.web.bind.annotation.RequestParam;
  14. import org.springframework.web.bind.annotation.ResponseBody;
  15. import java.util.List;
  16. /**
  17. * 文章页鉴于seo,保留旧链接
  18. *
  19. * @author : Charles
  20. * @date : 2020/7/31
  21. */
  22. @Controller
  23. public class ArticleController extends BaseController {
  24. private static final String ARTICLE_LIST_PATH = "article/list";
  25. private static final String ARTICLE_DETAIL_PATH = "article/detail";
  26. private ArticleService articleService;
  27. @Autowired
  28. public void setArticleService(ArticleService articleService) {
  29. this.articleService = articleService;
  30. }
  31. /**
  32. * 文章列表【旧center】
  33. */
  34. @GetMapping("/info/center-{id}-1.html")
  35. public String toArticleList(@PathVariable("id") Integer id, final Model model) {
  36. List<BaseLink> typeList = articleService.getArticleTypes();
  37. model.addAttribute("articleType", typeList);
  38. model.addAttribute("typeId", id);
  39. model.addAttribute("labelId", 0);
  40. return ARTICLE_LIST_PATH;
  41. }
  42. /**
  43. * 文章列表【旧label】
  44. */
  45. @GetMapping("/info/label-{id}-1.html")
  46. public String toArticleLabel(@PathVariable("id") Integer id, final Model model) {
  47. List<BaseLink> typeList = articleService.getArticleTypes();
  48. model.addAttribute("articleType", typeList);
  49. model.addAttribute("typeId", 0);
  50. model.addAttribute("labelId", id);
  51. return ARTICLE_LIST_PATH;
  52. }
  53. /**
  54. * 文章搜索结果
  55. */
  56. @GetMapping("/info/search.html")
  57. public String toArticleSearch(final Model model) {
  58. List<BaseLink> typeList = articleService.getArticleTypes();
  59. model.addAttribute("articleType", typeList);
  60. model.addAttribute("typeId", 0);
  61. model.addAttribute("labelId", 0);
  62. return ARTICLE_LIST_PATH;
  63. }
  64. /**
  65. * 文章详情【旧】
  66. */
  67. @GetMapping("/info/detail-{id}-1.html")
  68. public String toArticleDetail(@PathVariable("id") Integer id, final Model model) {
  69. model.addAttribute("articleId", id);
  70. return ARTICLE_DETAIL_PATH;
  71. }
  72. /**
  73. * 获取文章热门标签
  74. */
  75. @GetMapping("/article/labels")
  76. @ResponseBody
  77. public JsonModel<List<BaseLink>> getArticleLabels() {
  78. return articleService.getArticleLabels();
  79. }
  80. /**
  81. * 获取文章推荐
  82. */
  83. @GetMapping("/article/recommend")
  84. @ResponseBody
  85. public JsonModel<PageInfo<ImageLink>> getArticleRecommended(Integer typeId,
  86. @RequestParam(value = "pageNum", defaultValue = "1") int pageNum,
  87. @RequestParam(value = "pageSize", defaultValue = "3") int pageSize) {
  88. return articleService.getArticleRecommended(typeId, pageNum, pageSize);
  89. }
  90. /**
  91. * 获取文章广告
  92. */
  93. @GetMapping("/article/ads")
  94. @ResponseBody
  95. public JsonModel<List<ImageLink>> getLastestInfoAds() {
  96. return articleService.getLastestInfoAds();
  97. }
  98. /**
  99. * 点击标签
  100. */
  101. @GetMapping("/article/label/click")
  102. @ResponseBody
  103. public JsonModel clickArticleLabel(Integer id){
  104. return articleService.clickArticleLabel(id);
  105. }
  106. /**
  107. * 点击广告
  108. */
  109. @GetMapping("/article/ad/click")
  110. @ResponseBody
  111. public JsonModel clickArticleAd(Integer id){
  112. return articleService.clickArticleAd(id);
  113. }
  114. }