python222网站实战(SpringBoot+SpringSecurity+MybatisPlus+thymeleaf+layui)-帖子管理实现

锋哥原创的Springboot+Layui python222网站实战:

python222网站实战课程视频教程(SpringBoot+Python爬虫实战) ( 火爆连载更新中... )_哔哩哔哩_bilibilipython222网站实战课程视频教程(SpringBoot+Python爬虫实战) ( 火爆连载更新中... )共计23条视频,包括:python222网站实战课程视频教程(SpringBoot+Python爬虫实战) ( 火爆连载更新中... )、第2讲 架构搭建实现、第3讲 页面系统属性动态化设计实现等,UP主更多精彩视频,请关注UP账号。icon-default.png?t=N7T8https://www.bilibili.com/video/BV1yX4y1a7qM/python222网站实战(SpringBoot+SpringSecurity+MybatisPlus+thymeleaf+layui)-帖子管理实现_第1张图片

新建ArticleAdminController

package com.python222.controller.admin;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.python222.entity.Article;
import com.python222.entity.PageBean;
import com.python222.service.ArticleService;
import com.python222.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * 管理员-帖子控制器
 * @author python222小锋老师
 * @site www.python222.com
 */
@RestController
@RequestMapping(value = "/admin/article")
public class ArticleAdminController {

    @Autowired
    private ArticleService articleService;

    /**
     * 根据条件分页查询帖子
     * @param page
     * @param limit
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/list")
    public Map list(@RequestParam(value="page",required=false)Integer page,@RequestParam(value="limit",required=false)Integer limit, @RequestParam(value="title",required=false)String title)throws Exception{
        Map resultMap = new HashMap<>();
        PageBean pageBean=new PageBean(page,limit);
        Page
articlePage = articleService.page(new Page<>(pageBean.getPage(), pageBean.getPageSize()),new QueryWrapper
().like(StringUtil.isNotEmpty(title),"title",title).orderByDesc("publish_date")); resultMap.put("code", 0); resultMap.put("count", articlePage.getTotal()); resultMap.put("data", articlePage.getRecords()); return resultMap; } /** * 删除帖子 * @param id * @return * @throws Exception */ @RequestMapping("/delete") public Map delete(Integer id)throws Exception{ Map resultMap = new HashMap<>(); articleService.removeById(id); resultMap.put("success", true); return resultMap; } /** * 根据id查询帖子实体 * @param id * @return * @throws Exception */ @RequestMapping("/findById") public Map findById(Integer id)throws Exception{ Map resultMap = new HashMap<>(); Article article=articleService.getById(id); resultMap.put("article", article); resultMap.put("success", true); return resultMap; } }

新建articleManage.html





帖子管理





   

   
首页 帖子管理
/**
 * 修改帖子热门状态
 * @param article
 * @return
 */
@RequestMapping("/updateHotState")
public Map updateHotState(Article article){
    Article oldArticle = articleService.getById(article.getId());
    oldArticle.setHot(article.getHot());
    oldArticle.setHotDate(new Date());
    articleService.updateById(oldArticle);

    Map resultMap = new HashMap<>();
    resultMap.put("success",true);
    return resultMap;
}

你可能感兴趣的:(java,spring,boot,layui,java)