资源下载链路打通
This commit is contained in:
83
src/main/java/com/quinn/controller/SourceController.java
Normal file
83
src/main/java/com/quinn/controller/SourceController.java
Normal file
@@ -0,0 +1,83 @@
|
||||
package com.quinn.controller;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
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;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author limqsh
|
||||
* @since 2022-05-03
|
||||
*/
|
||||
@Controller
|
||||
public class SourceController {
|
||||
|
||||
@Resource
|
||||
SourceService sourceService;
|
||||
|
||||
@Resource
|
||||
SourceCategoryService sourceCategoryService;
|
||||
|
||||
@Resource
|
||||
SourceCommentService sourceCommentService;
|
||||
|
||||
// 列表展示
|
||||
@GetMapping("/source")
|
||||
public String blogList(@RequestParam String name,@RequestParam int category,Model model){
|
||||
System.out.println(name + category);
|
||||
Page<Source> pageParam = new Page<>(1, 10);
|
||||
QueryWrapper<Source> sourceQuery = new QueryWrapper<>();
|
||||
sourceQuery.orderByDesc("gmt_create");
|
||||
sourceService.page(pageParam,sourceQuery);
|
||||
// 结果
|
||||
List<Source> sourceList = pageParam.getRecords();
|
||||
model.addAttribute("sourceList",sourceList);
|
||||
model.addAttribute("pageParam",pageParam);
|
||||
|
||||
// 分类信息
|
||||
List<SourceCategory> categoryList = sourceCategoryService.list(null);
|
||||
model.addAttribute("categoryList",categoryList);
|
||||
|
||||
return "source/list";
|
||||
}
|
||||
|
||||
// 查看文件详情
|
||||
@GetMapping("/source/view/{sid}")
|
||||
public String read(@PathVariable("sid") String sid, Model model){
|
||||
Source source = sourceService.getOne(new QueryWrapper<Source>().eq("id", sid));
|
||||
source.setSourceLink("no network link");
|
||||
model.addAttribute("source",source);
|
||||
List<SourceComment> commentList = sourceCommentService.list(new QueryWrapper<SourceComment>().eq("topic_id", sid).orderByDesc("gmt_create"));
|
||||
model.addAttribute("commentList",commentList);
|
||||
return "source/view";
|
||||
}
|
||||
|
||||
// 下载文件
|
||||
@GetMapping("/source/download/{sid}")
|
||||
public void read(HttpServletResponse response, @PathVariable("sid") String sid) throws IOException {
|
||||
//通知浏览器以附件形式下载
|
||||
response.setHeader("Content-Disposition",
|
||||
"attachment;filename=" + UUIDGenerator.randomUUID());
|
||||
this.sourceService.downloadSource(response.getOutputStream(),sid);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user