From cf985bd44f76539a7762d4b770f853a9447d559a Mon Sep 17 00:00:00 2001 From: limqhz Date: Tue, 3 May 2022 21:15:47 +0800 Subject: [PATCH] =?UTF-8?q?=E6=90=9E=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/quinn/common/QuinnConstant.java | 2 + .../quinn/controller/SourceController.java | 73 ++++++++++++++++--- src/main/java/com/quinn/pojo/Source.java | 6 ++ .../com/quinn/pojo/param/QuerySource.java | 25 +++++++ .../quinn/service/impl/SourceServiceImpl.java | 2 - src/main/resources/templates/blog/read.html | 2 +- .../resources/templates/common/header.html | 6 +- .../resources/templates/question/read.html | 2 +- .../source/{hotpot.html => hotspot.html} | 23 +++--- src/main/resources/templates/source/list.html | 47 ++++++++++-- src/main/resources/templates/source/view.html | 11 +-- 11 files changed, 155 insertions(+), 44 deletions(-) create mode 100644 src/main/java/com/quinn/pojo/param/QuerySource.java rename src/main/resources/templates/source/{hotpot.html => hotspot.html} (57%) diff --git a/src/main/java/com/quinn/common/QuinnConstant.java b/src/main/java/com/quinn/common/QuinnConstant.java index d446c6c..8793500 100644 --- a/src/main/java/com/quinn/common/QuinnConstant.java +++ b/src/main/java/com/quinn/common/QuinnConstant.java @@ -4,4 +4,6 @@ public interface QuinnConstant { String LINK_SUFFIX = "."; + String GUN = "The emperor's new clothes"; + } diff --git a/src/main/java/com/quinn/controller/SourceController.java b/src/main/java/com/quinn/controller/SourceController.java index a7c6a16..5679e46 100644 --- a/src/main/java/com/quinn/controller/SourceController.java +++ b/src/main/java/com/quinn/controller/SourceController.java @@ -5,14 +5,15 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.quinn.common.QuinnConstant; import com.quinn.pojo.*; +import com.quinn.pojo.param.QuerySource; import com.quinn.service.SourceCategoryService; import com.quinn.service.SourceCommentService; import com.quinn.service.SourceService; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.util.CollectionUtils; +import org.springframework.util.StringUtils; +import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.servlet.http.HttpServletResponse; @@ -41,13 +42,18 @@ public class SourceController { // 列表展示 @GetMapping("/source") - public String sourceList(@RequestParam String name,@RequestParam int category,Model model){ + public String sourceList(Model model){ Page pageParam = new Page<>(1, 10); QueryWrapper sourceQuery = new QueryWrapper<>(); sourceQuery.orderByDesc("gmt_create"); sourceService.page(pageParam,sourceQuery); // 结果 List sourceList = pageParam.getRecords(); + if (!CollectionUtils.isEmpty(sourceList)){ + sourceList.forEach(x ->{ + x.setSourceLink(QuinnConstant.GUN); + }); + } model.addAttribute("sourceList",sourceList); model.addAttribute("pageParam",pageParam); @@ -58,32 +64,70 @@ public class SourceController { return "source/list"; } + @PostMapping("/source/page") + public String blogListPage(QuerySource querySource, Model model){ + int page = querySource.getPageNum(); + int limit = querySource.getLimit(); + if (querySource.getPageNum() < 1){ + page = 1; + } + Page pageParam = new Page<>(page, limit); + QueryWrapper sourceQuery = new QueryWrapper<>(); + addParam(sourceQuery,querySource.getName(),querySource.getCategory()); + sourceQuery.orderByDesc("gmt_create"); + sourceService.page(pageParam,sourceQuery); + + // 结果 + List blogList = pageParam.getRecords(); + model.addAttribute("sourceList",blogList); + model.addAttribute("pageParam",pageParam); + return "source/list::s_table_refresh"; + } + // 列表展示 - @GetMapping("/hot/source") + @GetMapping("/hotspot") public String sourceHotPot(Model model){ - Page pageParam = new Page<>(1, 10); + Page pageParam = new Page<>(1, 9); QueryWrapper sourceQuery = new QueryWrapper<>(); sourceQuery.orderByDesc("down_record"); sourceService.page(pageParam,sourceQuery); // 结果 List sourceList = pageParam.getRecords(); + if (!CollectionUtils.isEmpty(sourceList)){ + sourceList.forEach(x ->{ + x.setSourceLink(QuinnConstant.GUN); + x.setSourceContent(""); + }); + } model.addAttribute("sourceList",sourceList); - return "source/list"; + return "source/hotspot"; } - // 查看文件详情 + /** + * 查看下载资源的详情 + * @param sid + * @param model + * @return + */ @GetMapping("/source/view/{sid}") public String read(@PathVariable("sid") String sid, Model model){ Source source = sourceService.getOne(new QueryWrapper().eq("id", sid)); - source.setSourceLink("no network link"); + if(source != null){ + source.setSourceLink(QuinnConstant.GUN); + } model.addAttribute("source",source); List commentList = sourceCommentService.list(new QueryWrapper().eq("topic_id", sid).orderByDesc("gmt_create")); model.addAttribute("commentList",commentList); return "source/view"; } - // 下载文件 + /** + * 下载具体的文件 + * @param response + * @param sid + * @throws IOException + */ @GetMapping("/source/download/{sid}") public void read(HttpServletResponse response, @PathVariable("sid") String sid) throws IOException { Source source = sourceService.getOne(new QueryWrapper().eq("id", sid)); @@ -93,4 +137,13 @@ public class SourceController { this.sourceService.downloadSource(response.getOutputStream(),source); } + private void addParam(QueryWrapper sourceQuery, String name, int category) { + if (!StringUtils.isEmpty(name)){ + sourceQuery.like("source_name",name); + } + if (category > 0){ + sourceQuery.eq("category_id",category); + } + } + } diff --git a/src/main/java/com/quinn/pojo/Source.java b/src/main/java/com/quinn/pojo/Source.java index 751c8bc..cc96267 100644 --- a/src/main/java/com/quinn/pojo/Source.java +++ b/src/main/java/com/quinn/pojo/Source.java @@ -34,6 +34,9 @@ public class Source implements Serializable { @ApiModelProperty(value = "资源名") private String sourceName; + @ApiModelProperty(value = "描述") + private String detail; + @ApiModelProperty(value = "资源内容") private String sourceContent; @@ -64,6 +67,9 @@ public class Source implements Serializable { @ApiModelProperty(value = "文件后缀") private String fileType; + @ApiModelProperty(value = "下载次数") + private Integer downRecord; + @ApiModelProperty(value = "创建时间") private Date gmtCreate; diff --git a/src/main/java/com/quinn/pojo/param/QuerySource.java b/src/main/java/com/quinn/pojo/param/QuerySource.java new file mode 100644 index 0000000..c94d5ae --- /dev/null +++ b/src/main/java/com/quinn/pojo/param/QuerySource.java @@ -0,0 +1,25 @@ +package com.quinn.pojo.param; + +import lombok.Data; + +@Data +public class QuerySource { + + /** + * 模糊查询名称 + */ + private String name; + /** + * 资源类别 + */ + private int category; + /** + * 页码 + */ + private int pageNum; + /** + * 每页数量 + */ + private int limit; + +} diff --git a/src/main/java/com/quinn/service/impl/SourceServiceImpl.java b/src/main/java/com/quinn/service/impl/SourceServiceImpl.java index cf64c04..171d452 100644 --- a/src/main/java/com/quinn/service/impl/SourceServiceImpl.java +++ b/src/main/java/com/quinn/service/impl/SourceServiceImpl.java @@ -1,6 +1,5 @@ package com.quinn.service.impl; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.quinn.pojo.Source; import com.quinn.mapper.SourceMapper; import com.quinn.service.SourceService; @@ -13,7 +12,6 @@ import javax.servlet.ServletOutputStream; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.IOException; -import java.io.OutputStream; /** *

diff --git a/src/main/resources/templates/blog/read.html b/src/main/resources/templates/blog/read.html index 5f52c53..887f2f5 100644 --- a/src/main/resources/templates/blog/read.html +++ b/src/main/resources/templates/blog/read.html @@ -103,7 +103,7 @@

-
emmm... 这里暂时还没有评论....
+
还没有人评论,抢个沙发?
diff --git a/src/main/resources/templates/common/header.html b/src/main/resources/templates/common/header.html index 802ec70..1018db7 100644 --- a/src/main/resources/templates/common/header.html +++ b/src/main/resources/templates/common/header.html @@ -26,11 +26,11 @@
  • 博客
  • -
  • - 热门资源 +
  • + 热门资源
  • - 资源库 + 资源库
  • 关于 diff --git a/src/main/resources/templates/question/read.html b/src/main/resources/templates/question/read.html index 3ad2c07..0e71052 100644 --- a/src/main/resources/templates/question/read.html +++ b/src/main/resources/templates/question/read.html @@ -103,7 +103,7 @@
    -
    emmm... 这里暂时还没有评论....
    +
    还没有人评论,抢个沙发?
    diff --git a/src/main/resources/templates/source/hotpot.html b/src/main/resources/templates/source/hotspot.html similarity index 57% rename from src/main/resources/templates/source/hotpot.html rename to src/main/resources/templates/source/hotspot.html index 802d361..f267c94 100644 --- a/src/main/resources/templates/source/hotpot.html +++ b/src/main/resources/templates/source/hotspot.html @@ -5,12 +5,12 @@ 资源库-Quinn - + -
    +
    @@ -18,17 +18,18 @@ 需要什么资料请提交论坛,或者关注公众号反馈!我们会及时更新!
    -
    -
    -
    -

    -
    -
    diff --git a/src/main/resources/templates/source/list.html b/src/main/resources/templates/source/list.html index 0213b22..9e35c80 100644 --- a/src/main/resources/templates/source/list.html +++ b/src/main/resources/templates/source/list.html @@ -14,7 +14,7 @@
    -
    +
    @@ -31,7 +31,8 @@
    类别
    - +
    @@ -43,13 +44,13 @@
    -
    +
    - + @@ -58,7 +59,7 @@ - +
    # 资源名资源内容资源简介 资源类型 去下载
    详情 @@ -66,6 +67,25 @@
    +
    @@ -77,6 +97,21 @@ - + diff --git a/src/main/resources/templates/source/view.html b/src/main/resources/templates/source/view.html index f4f63eb..1797610 100644 --- a/src/main/resources/templates/source/view.html +++ b/src/main/resources/templates/source/view.html @@ -5,15 +5,6 @@ 资源下载-Quinn - - @@ -77,7 +68,7 @@
    -
    emmm... 这里暂时还没有评论....
    +
    还没有人评论,抢个沙发?