对博客进行了优化置顶,收藏,热度等操作
This commit is contained in:
@@ -20,4 +20,11 @@ public interface QuinnConstant {
|
||||
*/
|
||||
String SOURCE_PASSWORD = "926462";
|
||||
|
||||
String APPEND_PASSWORD = "wangna&limengqi";
|
||||
|
||||
String NEW_SOURCE_PASSWORD = "limengqi&wangna";
|
||||
|
||||
String EDIT_SOURCE_FIRST = "lw@";
|
||||
String EDIT_SOURCE_LAST = "#";
|
||||
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ public class AboutController {
|
||||
|
||||
@GetMapping("/about")
|
||||
public String userIndexBlog(Model model){
|
||||
Page<About> pageParam = new Page<>(1, 50);
|
||||
Page<About> pageParam = new Page<>(1, 20);
|
||||
aboutService.page(pageParam,new QueryWrapper<About>().orderByDesc("gmt_create"));
|
||||
// 结果
|
||||
List<About> sayList = pageParam.getRecords();
|
||||
|
||||
17
src/main/java/com/quinn/controller/BaseModelController.java
Normal file
17
src/main/java/com/quinn/controller/BaseModelController.java
Normal file
@@ -0,0 +1,17 @@
|
||||
package com.quinn.controller;
|
||||
|
||||
import com.quinn.pojo.User;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
public class BaseModelController {
|
||||
|
||||
protected String getLoginUserId(HttpServletRequest request){
|
||||
User user = (User) request.getSession().getAttribute("loginUser");
|
||||
if (user != null){
|
||||
return user.getUid();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -23,7 +23,7 @@ import java.util.List;
|
||||
* @author limqsh
|
||||
* @since 2020-06-29
|
||||
*/
|
||||
@Controller
|
||||
//@Controller
|
||||
public class BlogCategoryController {
|
||||
|
||||
@Autowired
|
||||
@@ -31,7 +31,8 @@ public class BlogCategoryController {
|
||||
@Autowired
|
||||
BlogService blogService;
|
||||
|
||||
@GetMapping("/blog/category/{bid}/{page}/{limit}")
|
||||
@Deprecated
|
||||
// @GetMapping("/blog/category/{bid}/{page}/{limit}")
|
||||
public String blogPage(
|
||||
@PathVariable int bid,
|
||||
@PathVariable int page,
|
||||
|
||||
@@ -5,17 +5,26 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.quinn.pojo.Blog;
|
||||
import com.quinn.pojo.BlogCategory;
|
||||
import com.quinn.pojo.BlogStar;
|
||||
import com.quinn.pojo.Comment;
|
||||
import com.quinn.service.BlogCategoryService;
|
||||
import com.quinn.service.BlogService;
|
||||
import com.quinn.service.BlogStarService;
|
||||
import com.quinn.service.CommentService;
|
||||
import com.quinn.utils.QuinnUtils;
|
||||
import com.quinn.vo.BlogStarReq;
|
||||
import com.quinn.vo.QuestionWriteForm;
|
||||
import com.quinn.vo.StarValue;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -27,7 +36,7 @@ import java.util.List;
|
||||
* @since 2020-06-29
|
||||
*/
|
||||
@Controller
|
||||
public class BlogController {
|
||||
public class BlogController extends BaseModelController{
|
||||
|
||||
@Autowired
|
||||
BlogCategoryService blogCategoryService;
|
||||
@@ -35,18 +44,23 @@ public class BlogController {
|
||||
BlogService blogService;
|
||||
@Autowired
|
||||
CommentService commentService;
|
||||
@Resource
|
||||
BlogStarService blogStarService;
|
||||
|
||||
// 列表展示
|
||||
@GetMapping("/blog")
|
||||
public String blogList(Model model){
|
||||
|
||||
Page<Blog> pageParam = new Page<>(1, 10);
|
||||
blogService.page(pageParam,new QueryWrapper<Blog>().orderByDesc("gmt_create"));
|
||||
blogService.page(pageParam,new QueryWrapper<Blog>().orderByDesc("sort").orderByDesc("gmt_create"));
|
||||
// 结果
|
||||
List<Blog> blogList = pageParam.getRecords();
|
||||
model.addAttribute("blogList",blogList);
|
||||
model.addAttribute("pageParam",pageParam);
|
||||
|
||||
List<Blog> topBlogList = blogService.getTopBlog();
|
||||
model.addAttribute("topBlogList",topBlogList);
|
||||
|
||||
// 分类信息
|
||||
List<BlogCategory> categoryList = blogCategoryService.list(null);
|
||||
model.addAttribute("categoryList",categoryList);
|
||||
@@ -64,13 +78,16 @@ public class BlogController {
|
||||
page = 1;
|
||||
}
|
||||
Page<Blog> pageParam = new Page<>(page, limit);
|
||||
blogService.page(pageParam,new QueryWrapper<Blog>().orderByDesc("gmt_create"));
|
||||
blogService.page(pageParam,new QueryWrapper<Blog>().orderByDesc("sort").orderByDesc("gmt_create"));
|
||||
|
||||
// 结果
|
||||
List<Blog> blogList = pageParam.getRecords();
|
||||
model.addAttribute("blogList",blogList);
|
||||
model.addAttribute("pageParam",pageParam);
|
||||
|
||||
List<Blog> topBlogList = blogService.getTopBlog();
|
||||
model.addAttribute("topBlogList",topBlogList);
|
||||
|
||||
// 分类信息
|
||||
List<BlogCategory> categoryList = blogCategoryService.list(null);
|
||||
model.addAttribute("categoryList",categoryList);
|
||||
@@ -115,16 +132,52 @@ public class BlogController {
|
||||
|
||||
// 阅读文章
|
||||
@GetMapping("/blog/read/{bid}")
|
||||
public String read(@PathVariable("bid") String bid,Model model){
|
||||
public String read(HttpServletRequest request, @PathVariable("bid") String bid, Model model){
|
||||
Blog blog = blogService.getOne(new QueryWrapper<Blog>().eq("bid", bid));
|
||||
blog.setViews(blog.getViews()+1);
|
||||
blogService.updateById(blog);
|
||||
model.addAttribute("blog",blog);
|
||||
|
||||
StarValue starValue = new StarValue();
|
||||
starValue.setStar(false);
|
||||
String loginUserId = getLoginUserId(request);
|
||||
if (!StringUtils.isEmpty(loginUserId)){
|
||||
List<BlogStar> stars = blogStarService.list(new QueryWrapper<BlogStar>().eq("user_id", loginUserId));
|
||||
if (!CollectionUtils.isEmpty(stars)){
|
||||
starValue.setStar(true);
|
||||
}
|
||||
}
|
||||
model.addAttribute("starValue",starValue);
|
||||
|
||||
List<Comment> commentList = commentService.list(new QueryWrapper<Comment>().eq("topic_id", bid).orderByDesc("gmt_create"));
|
||||
model.addAttribute("commentList",commentList);
|
||||
return "blog/read";
|
||||
}
|
||||
|
||||
// 收藏
|
||||
@PostMapping("/blog/star")
|
||||
public synchronized String toStar(BlogStarReq blogStarReq, Model model){
|
||||
StarValue starValue = new StarValue();
|
||||
starValue.setStar(false);
|
||||
List<BlogStar> list = blogStarService.list(new QueryWrapper<BlogStar>()
|
||||
.eq("user_id", blogStarReq.getUserId()).eq("topic_id", blogStarReq.getTopicId()));
|
||||
if (!CollectionUtils.isEmpty(list)){
|
||||
list.forEach(x->{
|
||||
blogStarService.removeById(x);
|
||||
});
|
||||
starValue.setStar(false);
|
||||
} else {
|
||||
BlogStar blogStar = new BlogStar();
|
||||
blogStar.setTopicId(blogStarReq.getTopicId());
|
||||
blogStar.setUserId(blogStarReq.getUserId());
|
||||
blogStar.setGmtCreate(QuinnUtils.getTime());
|
||||
blogStarService.save(blogStar);
|
||||
starValue.setStar(true);
|
||||
}
|
||||
model.addAttribute("starValue",starValue);
|
||||
return "blog/read::star_refresh";
|
||||
}
|
||||
|
||||
// 编辑问题
|
||||
@GetMapping("/blog/editor/{uid}/{bid}")
|
||||
public synchronized String toEditor(@PathVariable("uid") String uid,
|
||||
@@ -188,8 +241,5 @@ public class BlogController {
|
||||
return "redirect:/blog/read/"+bid;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
59
src/main/java/com/quinn/controller/SearchController.java
Normal file
59
src/main/java/com/quinn/controller/SearchController.java
Normal file
@@ -0,0 +1,59 @@
|
||||
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.About;
|
||||
import com.quinn.pojo.Source;
|
||||
import com.quinn.service.SourceService;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author limqsh
|
||||
* @since 2022-05-01
|
||||
*/
|
||||
@Controller
|
||||
public class SearchController {
|
||||
|
||||
@Resource
|
||||
SourceService sourceService;
|
||||
|
||||
@PostMapping("/search")
|
||||
public String searchAll(String findWhat,Model model){
|
||||
if (StringUtils.isEmpty(findWhat)){
|
||||
return "index";
|
||||
}
|
||||
if (QuinnConstant.NEW_SOURCE_PASSWORD.equals(findWhat)){
|
||||
return "source/uploadSource";
|
||||
}
|
||||
if (QuinnConstant.APPEND_PASSWORD.equals(findWhat)){
|
||||
return "page/append";
|
||||
}
|
||||
if (findWhat.startsWith(QuinnConstant.EDIT_SOURCE_FIRST)){
|
||||
findWhat = findWhat.substring(findWhat.indexOf(QuinnConstant.EDIT_SOURCE_FIRST) + QuinnConstant.EDIT_SOURCE_FIRST.length());
|
||||
if (!StringUtils.isEmpty(findWhat) && findWhat.endsWith(QuinnConstant.EDIT_SOURCE_LAST)){
|
||||
findWhat = findWhat.substring(0,findWhat.lastIndexOf(QuinnConstant.EDIT_SOURCE_LAST));
|
||||
}
|
||||
if (!StringUtils.isEmpty(findWhat)){
|
||||
Source sid = sourceService.getOne(new QueryWrapper<Source>().eq("sid", findWhat));
|
||||
if (sid!=null){
|
||||
return "redirect:/tracy/mcgrady/lmq/love/wn/" + findWhat;
|
||||
}
|
||||
}
|
||||
}
|
||||
return "index";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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");//设置要映射的表名
|
||||
strategy.setInclude("qn_blog_star");//设置要映射的表名
|
||||
strategy.setNaming(NamingStrategy.underline_to_camel);//数据库表映射到实体的命名策略
|
||||
strategy.setTablePrefix("qn_");//设置表前缀不生成
|
||||
|
||||
|
||||
@@ -3,6 +3,8 @@ package com.quinn.mapper;
|
||||
import com.quinn.pojo.Blog;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Mapper 接口
|
||||
@@ -13,4 +15,5 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
*/
|
||||
public interface BlogMapper extends BaseMapper<Blog> {
|
||||
|
||||
List<Blog> getTopBlog();
|
||||
}
|
||||
|
||||
16
src/main/java/com/quinn/mapper/BlogStarMapper.java
Normal file
16
src/main/java/com/quinn/mapper/BlogStarMapper.java
Normal file
@@ -0,0 +1,16 @@
|
||||
package com.quinn.mapper;
|
||||
|
||||
import com.quinn.pojo.BlogStar;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author limqsh
|
||||
* @since 2022-05-08
|
||||
*/
|
||||
public interface BlogStarMapper extends BaseMapper<BlogStar> {
|
||||
|
||||
}
|
||||
@@ -2,4 +2,9 @@
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.quinn.mapper.BlogMapper">
|
||||
|
||||
<select id="getTopBlog" resultType="com.quinn.pojo.Blog">
|
||||
select bid,title,(star + views) as views from qn_blog where sort = 0
|
||||
order by (star + views) desc limit 5;
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
|
||||
@@ -44,6 +44,9 @@ public class Blog implements Serializable {
|
||||
@ApiModelProperty(value = "排序 0 普通 1 置顶")
|
||||
private Integer sort;
|
||||
|
||||
@ApiModelProperty(value = "收藏")
|
||||
private Integer star;
|
||||
|
||||
@ApiModelProperty(value = "浏览量")
|
||||
private Integer views;
|
||||
|
||||
|
||||
45
src/main/java/com/quinn/pojo/BlogStar.java
Normal file
45
src/main/java/com/quinn/pojo/BlogStar.java
Normal file
@@ -0,0 +1,45 @@
|
||||
package com.quinn.pojo;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import java.util.Date;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import java.io.Serializable;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
*
|
||||
* </p>
|
||||
*
|
||||
* @author limqsh
|
||||
* @since 2022-05-08
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Accessors(chain = true)
|
||||
@TableName("qn_blog_star")
|
||||
@ApiModel(value="BlogStar对象", description="")
|
||||
public class BlogStar implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@ApiModelProperty(value = "自增id")
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Integer id;
|
||||
|
||||
@ApiModelProperty(value = "收藏主题id")
|
||||
private String topicId;
|
||||
|
||||
@ApiModelProperty(value = "收藏者id")
|
||||
private String userId;
|
||||
|
||||
@ApiModelProperty(value = "收藏创建时间")
|
||||
private Date gmtCreate;
|
||||
|
||||
|
||||
}
|
||||
@@ -3,6 +3,8 @@ package com.quinn.service;
|
||||
import com.quinn.pojo.Blog;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务类
|
||||
@@ -13,4 +15,6 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
||||
*/
|
||||
public interface BlogService extends IService<Blog> {
|
||||
|
||||
List<Blog> getTopBlog();
|
||||
|
||||
}
|
||||
|
||||
16
src/main/java/com/quinn/service/BlogStarService.java
Normal file
16
src/main/java/com/quinn/service/BlogStarService.java
Normal file
@@ -0,0 +1,16 @@
|
||||
package com.quinn.service;
|
||||
|
||||
import com.quinn.pojo.BlogStar;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author limqsh
|
||||
* @since 2022-05-08
|
||||
*/
|
||||
public interface BlogStarService extends IService<BlogStar> {
|
||||
|
||||
}
|
||||
@@ -5,6 +5,11 @@ import com.quinn.mapper.BlogMapper;
|
||||
import com.quinn.service.BlogService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -17,4 +22,18 @@ import org.springframework.stereotype.Service;
|
||||
@Service
|
||||
public class BlogServiceImpl extends ServiceImpl<BlogMapper, Blog> implements BlogService {
|
||||
|
||||
@Resource
|
||||
BlogMapper blogMapper;
|
||||
|
||||
@Override
|
||||
public List<Blog> getTopBlog(){
|
||||
List<Blog> topBlog = blogMapper.getTopBlog();
|
||||
if (!CollectionUtils.isEmpty(topBlog)){
|
||||
topBlog.forEach(x->{
|
||||
x.setContent("");
|
||||
});
|
||||
}
|
||||
return topBlog;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.quinn.service.impl;
|
||||
|
||||
import com.quinn.pojo.BlogStar;
|
||||
import com.quinn.mapper.BlogStarMapper;
|
||||
import com.quinn.service.BlogStarService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author limqsh
|
||||
* @since 2022-05-08
|
||||
*/
|
||||
@Service
|
||||
public class BlogStarServiceImpl extends ServiceImpl<BlogStarMapper, BlogStar> implements BlogStarService {
|
||||
|
||||
}
|
||||
19
src/main/java/com/quinn/vo/BlogStarReq.java
Normal file
19
src/main/java/com/quinn/vo/BlogStarReq.java
Normal file
@@ -0,0 +1,19 @@
|
||||
package com.quinn.vo;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Accessors(chain = true)
|
||||
public class BlogStarReq {
|
||||
|
||||
@ApiModelProperty(value = "主题号")
|
||||
private String topicId;
|
||||
|
||||
@ApiModelProperty(value = "用户编号")
|
||||
private String userId;
|
||||
|
||||
}
|
||||
16
src/main/java/com/quinn/vo/StarValue.java
Normal file
16
src/main/java/com/quinn/vo/StarValue.java
Normal file
@@ -0,0 +1,16 @@
|
||||
package com.quinn.vo;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Accessors(chain = true)
|
||||
public class StarValue {
|
||||
|
||||
@ApiModelProperty(value = "是否收藏")
|
||||
private boolean star;
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user