From 0eed40c97e086cb9c65f10b759f7830aefec450a Mon Sep 17 00:00:00 2001 From: limqhz Date: Tue, 3 May 2022 17:45:15 +0800 Subject: [PATCH] =?UTF-8?q?=E7=83=AD=E7=82=B9=E8=B5=84=E6=BA=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/quinn/common/QuinnConstant.java | 7 ++++++ .../quinn/controller/SourceController.java | 25 ++++++++++++++----- .../com/quinn/generator/CodeGenerator.java | 8 +++--- src/main/java/com/quinn/pojo/Source.java | 6 +++++ .../java/com/quinn/service/SourceService.java | 2 +- .../quinn/service/impl/SourceServiceImpl.java | 3 +-- .../download.html => source/hotpot.html} | 2 +- 7 files changed, 39 insertions(+), 14 deletions(-) create mode 100644 src/main/java/com/quinn/common/QuinnConstant.java rename src/main/resources/templates/{page/download.html => source/hotpot.html} (93%) diff --git a/src/main/java/com/quinn/common/QuinnConstant.java b/src/main/java/com/quinn/common/QuinnConstant.java new file mode 100644 index 0000000..d446c6c --- /dev/null +++ b/src/main/java/com/quinn/common/QuinnConstant.java @@ -0,0 +1,7 @@ +package com.quinn.common; + +public interface QuinnConstant { + + String LINK_SUFFIX = "."; + +} diff --git a/src/main/java/com/quinn/controller/SourceController.java b/src/main/java/com/quinn/controller/SourceController.java index 3c82256..a7c6a16 100644 --- a/src/main/java/com/quinn/controller/SourceController.java +++ b/src/main/java/com/quinn/controller/SourceController.java @@ -3,11 +3,11 @@ package com.quinn.controller; 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.service.SourceCategoryService; import com.quinn.service.SourceCommentService; import com.quinn.service.SourceService; -import com.quinn.utils.UUIDGenerator; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; @@ -41,8 +41,7 @@ public class SourceController { // 列表展示 @GetMapping("/source") - public String blogList(@RequestParam String name,@RequestParam int category,Model model){ - System.out.println(name + category); + public String sourceList(@RequestParam String name,@RequestParam int category,Model model){ Page pageParam = new Page<>(1, 10); QueryWrapper sourceQuery = new QueryWrapper<>(); sourceQuery.orderByDesc("gmt_create"); @@ -59,6 +58,20 @@ public class SourceController { return "source/list"; } + // 列表展示 + @GetMapping("/hot/source") + public String sourceHotPot(Model model){ + Page pageParam = new Page<>(1, 10); + QueryWrapper sourceQuery = new QueryWrapper<>(); + sourceQuery.orderByDesc("down_record"); + sourceService.page(pageParam,sourceQuery); + // 结果 + List sourceList = pageParam.getRecords(); + model.addAttribute("sourceList",sourceList); + return "source/list"; + } + + // 查看文件详情 @GetMapping("/source/view/{sid}") public String read(@PathVariable("sid") String sid, Model model){ @@ -73,11 +86,11 @@ public class SourceController { // 下载文件 @GetMapping("/source/download/{sid}") public void read(HttpServletResponse response, @PathVariable("sid") String sid) throws IOException { + Source source = sourceService.getOne(new QueryWrapper().eq("id", sid)); //通知浏览器以附件形式下载 response.setHeader("Content-Disposition", - "attachment;filename=" + UUIDGenerator.randomUUID()); - this.sourceService.downloadSource(response.getOutputStream(),sid); + "attachment;filename=" + source.getEnName() + QuinnConstant.LINK_SUFFIX + source.getFileType()); + this.sourceService.downloadSource(response.getOutputStream(),source); } } - diff --git a/src/main/java/com/quinn/generator/CodeGenerator.java b/src/main/java/com/quinn/generator/CodeGenerator.java index 8b68929..2ef7587 100644 --- a/src/main/java/com/quinn/generator/CodeGenerator.java +++ b/src/main/java/com/quinn/generator/CodeGenerator.java @@ -43,15 +43,15 @@ public class CodeGenerator { PackageConfig pc = new PackageConfig(); pc.setModuleName("quinn"); pc.setParent("com"); - pc.setController("controller"); +// pc.setController("controller"); pc.setEntity("pojo"); - pc.setService("service"); - pc.setMapper("mapper"); +// pc.setService("service"); +// pc.setMapper("mapper"); mpg.setPackageInfo(pc); // 5、策略配置 StrategyConfig strategy = new StrategyConfig(); - strategy.setInclude("qn_source_comment");//设置要映射的表名 + strategy.setInclude("qn_source");//设置要映射的表名 strategy.setNaming(NamingStrategy.underline_to_camel);//数据库表映射到实体的命名策略 strategy.setTablePrefix("qn_");//设置表前缀不生成 diff --git a/src/main/java/com/quinn/pojo/Source.java b/src/main/java/com/quinn/pojo/Source.java index a867e34..751c8bc 100644 --- a/src/main/java/com/quinn/pojo/Source.java +++ b/src/main/java/com/quinn/pojo/Source.java @@ -58,6 +58,12 @@ public class Source implements Serializable { @ApiModelProperty(value = "类别名") private String categoryName; + @ApiModelProperty(value = "英文名") + private String enName; + + @ApiModelProperty(value = "文件后缀") + private String fileType; + @ApiModelProperty(value = "创建时间") private Date gmtCreate; diff --git a/src/main/java/com/quinn/service/SourceService.java b/src/main/java/com/quinn/service/SourceService.java index a2b2bd2..e450e9e 100644 --- a/src/main/java/com/quinn/service/SourceService.java +++ b/src/main/java/com/quinn/service/SourceService.java @@ -17,6 +17,6 @@ import java.io.OutputStream; */ public interface SourceService extends IService { - void downloadSource(ServletOutputStream outputStream, String sid) throws IOException; + void downloadSource(ServletOutputStream outputStream, Source source) throws IOException; } diff --git a/src/main/java/com/quinn/service/impl/SourceServiceImpl.java b/src/main/java/com/quinn/service/impl/SourceServiceImpl.java index 6570df2..cf64c04 100644 --- a/src/main/java/com/quinn/service/impl/SourceServiceImpl.java +++ b/src/main/java/com/quinn/service/impl/SourceServiceImpl.java @@ -30,8 +30,7 @@ public class SourceServiceImpl extends ServiceImpl impleme OSSClientUtil ossClientUtil; @Override - public void downloadSource(ServletOutputStream outputStream, String sid) throws IOException { - Source source = getOne(new QueryWrapper().eq("id", sid)); + public void downloadSource(ServletOutputStream outputStream, Source source) throws IOException { String sourceLink = source.getSourceLink(); // 读取文件内容。 BufferedInputStream in = new BufferedInputStream(ossClientUtil.downloadFile(sourceLink)); diff --git a/src/main/resources/templates/page/download.html b/src/main/resources/templates/source/hotpot.html similarity index 93% rename from src/main/resources/templates/page/download.html rename to src/main/resources/templates/source/hotpot.html index d04189f..802d361 100644 --- a/src/main/resources/templates/page/download.html +++ b/src/main/resources/templates/source/hotpot.html @@ -15,7 +15,7 @@
- 资源慢慢日积月累,需要什么可以在群里@我,如果我有就放到这里! + 需要什么资料请提交论坛,或者关注公众号反馈!我们会及时更新!