搞定
This commit is contained in:
@@ -4,4 +4,6 @@ public interface QuinnConstant {
|
||||
|
||||
String LINK_SUFFIX = ".";
|
||||
|
||||
String GUN = "The emperor's new clothes";
|
||||
|
||||
}
|
||||
|
||||
@@ -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<Source> pageParam = new Page<>(1, 10);
|
||||
QueryWrapper<Source> sourceQuery = new QueryWrapper<>();
|
||||
sourceQuery.orderByDesc("gmt_create");
|
||||
sourceService.page(pageParam,sourceQuery);
|
||||
// 结果
|
||||
List<Source> 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<Source> pageParam = new Page<>(page, limit);
|
||||
QueryWrapper<Source> sourceQuery = new QueryWrapper<>();
|
||||
addParam(sourceQuery,querySource.getName(),querySource.getCategory());
|
||||
sourceQuery.orderByDesc("gmt_create");
|
||||
sourceService.page(pageParam,sourceQuery);
|
||||
|
||||
// 结果
|
||||
List<Source> 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<Source> pageParam = new Page<>(1, 10);
|
||||
Page<Source> pageParam = new Page<>(1, 9);
|
||||
QueryWrapper<Source> sourceQuery = new QueryWrapper<>();
|
||||
sourceQuery.orderByDesc("down_record");
|
||||
sourceService.page(pageParam,sourceQuery);
|
||||
// 结果
|
||||
List<Source> 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<Source>().eq("id", sid));
|
||||
source.setSourceLink("no network link");
|
||||
if(source != null){
|
||||
source.setSourceLink(QuinnConstant.GUN);
|
||||
}
|
||||
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";
|
||||
}
|
||||
|
||||
// 下载文件
|
||||
/**
|
||||
* 下载具体的文件
|
||||
* @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<Source>().eq("id", sid));
|
||||
@@ -93,4 +137,13 @@ public class SourceController {
|
||||
this.sourceService.downloadSource(response.getOutputStream(),source);
|
||||
}
|
||||
|
||||
private void addParam(QueryWrapper<Source> sourceQuery, String name, int category) {
|
||||
if (!StringUtils.isEmpty(name)){
|
||||
sourceQuery.like("source_name",name);
|
||||
}
|
||||
if (category > 0){
|
||||
sourceQuery.eq("category_id",category);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
25
src/main/java/com/quinn/pojo/param/QuerySource.java
Normal file
25
src/main/java/com/quinn/pojo/param/QuerySource.java
Normal file
@@ -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;
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
|
||||
@@ -103,7 +103,7 @@
|
||||
</div>
|
||||
<div th:if="${commentList.size()==0}" class="col-md-12 blog-main" style="margin-top: 20px">
|
||||
<div class="my-3 p-3 bg-white rounded shadow-sm">
|
||||
<h6 class="pb-2 mb-0 text-center">emmm... 这里暂时还没有评论....</h6>
|
||||
<h6 class="pb-2 mb-4 text-center">还没有人评论,抢个沙发?</h6>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -26,11 +26,11 @@
|
||||
<li th:class="${activeUrl=='blog'?'nav-item active':'nav-item'}">
|
||||
<a class="nav-link" th:href="@{/blog}">博客 </a>
|
||||
</li>
|
||||
<li th:class="${activeUrl=='download'?'nav-item active':'nav-item'}">
|
||||
<a class="nav-link" th:href="@{/download}">热门资源 </a>
|
||||
<li th:class="${activeUrl=='hotspot'?'nav-item active':'nav-item'}">
|
||||
<a class="nav-link" th:href="@{/hotspot}">热门资源 </a>
|
||||
</li>
|
||||
<li th:class="${activeUrl=='source'?'nav-item active':'nav-item'}">
|
||||
<a class="nav-link" th:href="@{/source?name=&category=0}">资源库 </a>
|
||||
<a class="nav-link" th:href="@{/source}">资源库 </a>
|
||||
</li>
|
||||
<li th:class="${activeUrl=='about'?'nav-item active':'nav-item'}">
|
||||
<a class="nav-link" th:href="@{/about}">关于 </a>
|
||||
|
||||
@@ -103,7 +103,7 @@
|
||||
</div>
|
||||
<div th:if="${commentList.size()==0}" class="col-md-12 blog-main" style="margin-top: 20px">
|
||||
<div class="my-3 p-3 bg-white rounded shadow-sm">
|
||||
<h6 class="pb-2 mb-0 text-center">emmm... 这里暂时还没有评论....</h6>
|
||||
<h6 class="pb-2 mb-4 text-center">还没有人评论,抢个沙发?</h6>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -5,12 +5,12 @@
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
<title>资源库-Quinn</title>
|
||||
<link rel="stylesheet" th:href="@{/bootstrap/css/bootstrap.min.css}">
|
||||
<link rel="stylesheet" th:href="@{/css/download.css}">
|
||||
<link rel="stylesheet" th:href="@{/css/source.css}">
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div th:replace="~{common/header::header(activeUrl='download')}"></div>
|
||||
<div th:replace="~{common/header::header(activeUrl='hotspot')}"></div>
|
||||
|
||||
<main role="main" class="mt-3">
|
||||
<div class="container">
|
||||
@@ -18,17 +18,18 @@
|
||||
需要什么资料请提交论坛,或者关注公众号反馈!我们会及时更新!
|
||||
</div>
|
||||
|
||||
<div class="card-deck mb-3 text-center">
|
||||
<div class="card mb-4 shadow-sm" th:each="download:${downloadList}">
|
||||
<div class="card-header">
|
||||
<h4 class="my-0 font-weight-normal" th:text="${download.getDname()}"></h4>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<p th:text="${download.getDdesc()}"></p>
|
||||
<a style="color: white" class="btn btn-sm btn-primary">提取码: [[${download.getDcode()}]]</a>
|
||||
<div class="row row-cols-1 row-cols-md-3 text-center">
|
||||
<div class="col mb-4" th:each="source:${sourceList}">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h4 class="font-weight-normal" th:text="${source.getSourceName()}"></h4>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<p th:text="${source.getDetail()}"></p>
|
||||
<a th:href="@{'/source/view/'+${source.getId()}}" style="color: white" class="btn btn-sm btn-primary">查看详情</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
<main role="main" class="mt-3">
|
||||
<div class="container">
|
||||
<form action="/source">
|
||||
<form action="javascript:navChange(0);" method="post">
|
||||
<div class="form-row align-items-center">
|
||||
<div class="col-auto">
|
||||
<label class="sr-only" for="name">KEYWORD</label>
|
||||
@@ -31,7 +31,8 @@
|
||||
<div class="input-group-prepend">
|
||||
<div class="input-group-text">类别</div>
|
||||
</div>
|
||||
<select id="category" name="category" class="form-control">
|
||||
<select id="category" name="category" class="form-control custom-select">
|
||||
<option th:value=-1 th:text="请选择"></option>
|
||||
<option th:each="category:${categoryList}" th:value="${category.getId()}" th:text="${category.getCategory()}"></option>
|
||||
</select>
|
||||
</div>
|
||||
@@ -43,13 +44,13 @@
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="container">
|
||||
<div class="container" th:fragment="s_table_refresh" th:id="id_s_table_refresh">
|
||||
<table class="table">
|
||||
<thead class="thead-light">
|
||||
<tr>
|
||||
<th scope="col">#</th>
|
||||
<th scope="col">资源名</th>
|
||||
<th scope="col">资源内容</th>
|
||||
<th scope="col">资源简介</th>
|
||||
<th scope="col">资源类型</th>
|
||||
<th scope="col">去下载</th>
|
||||
</tr>
|
||||
@@ -58,7 +59,7 @@
|
||||
<tr th:each="source:${sourceList}">
|
||||
<td th:text="${source.getId()}"></td>
|
||||
<td th:text="${source.getSourceName()}"></td>
|
||||
<td th:text="${source.getSourceContent()}"></td>
|
||||
<td th:text="${source.getDetail()}"></td>
|
||||
<td th:text="${source.getCategoryName()}"></td>
|
||||
<td th:name="${source.getId()}">
|
||||
<a style="color: white" th:href="@{'/source/view/'+${source.getId()}}" class="btn btn-sm btn-primary">详情</a>
|
||||
@@ -66,6 +67,25 @@
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<nav aria-label="Page navigation example">
|
||||
<ul class="pagination justify-content-center">
|
||||
<li th:class="${pageParam.hasPrevious()==true?'page-item':'page-item disabled'}">
|
||||
<a class="page-link" href="javascript:navChange(-1);" tabindex="">Previous</a>
|
||||
</li>
|
||||
<li class="page-item" th:if="${pageParam.hasPrevious()}">
|
||||
<a class="page-link" href="javascript:navChange(-1);" th:text="${pageParam.getCurrent()-1}"></a>
|
||||
</li>
|
||||
<li class="page-item active">
|
||||
<a id = "current" class="page-link" href="javascript:navChange(0);" th:text="${pageParam.getCurrent()}"></a>
|
||||
</li>
|
||||
<li class="page-item" th:if="${pageParam.hasNext()}">
|
||||
<a class="page-link" href="javascript:navChange(1);" th:text="${pageParam.getCurrent()+1}"></a>
|
||||
</li>
|
||||
<li th:class="${pageParam.hasNext()==true?'page-item':'page-item disabled'}">
|
||||
<a class="page-link" href="javascript:navChange(1);">Next</a>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
@@ -77,6 +97,21 @@
|
||||
<script th:src="@{/js/toTop.js}"></script>
|
||||
<script th:src="@{/js/jquery-ui.min.js}"></script>
|
||||
<script th:src="@{/live/js/addlive2d.js}"></script>
|
||||
|
||||
<script type="text/javascript">
|
||||
function navChange(page){
|
||||
var name = $('#name').attr("value");
|
||||
var category = $('#category').val();
|
||||
var current = $('#current').text();
|
||||
var pageNum = parseInt(current) + page;
|
||||
$.ajax({
|
||||
url: "/source/page",
|
||||
type: "post",
|
||||
data: {"name": name, "category": category, "pageNum": pageNum, "limit": 10},
|
||||
success: function (data) {
|
||||
$('#id_s_table_refresh').html(data);
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -5,15 +5,6 @@
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
<title>资源下载-Quinn</title>
|
||||
<link rel="stylesheet" th:href="@{/bootstrap/css/bootstrap.min.css}">
|
||||
|
||||
<style>
|
||||
.nav-underline .nav-link {
|
||||
padding-top: .75rem;
|
||||
padding-bottom: .75rem;
|
||||
font-size: .875rem;
|
||||
color: #6c757d;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body style="background: #f2f2f2;">
|
||||
|
||||
@@ -77,7 +68,7 @@
|
||||
</div>
|
||||
<div th:if="${commentList.size()==0}" class="col-md-12 source-main" style="margin-top: 20px">
|
||||
<div class="my-3 p-3 bg-white rounded shadow-sm">
|
||||
<h6 class="pb-2 mb-0 text-center">emmm... 这里暂时还没有评论....</h6>
|
||||
<h6 class="pb-2 mb-4 text-center">还没有人评论,抢个沙发?</h6>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user