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张图片

我们有些文章,比如自我介绍帖子,vip课程帖子,这种区别于正常发文文章的帖子,我们可以单独管理,设计成自定义帖子模块。

新建t_post表

create table `t_post` (
	`id` int (11),
	`title` varchar (600),
	`content` text 
); 
insert into `t_post` (`id`, `title`, `content`) values('2','2',NULL);
insert into `t_post` (`id`, `title`, `content`) values('3','3','

222

\n'); insert into `t_post` (`id`, `title`, `content`) values('5','4测试444','

32324444\"\"

\n');

用Mybatis-X生成代码;

新建PostAdminController类:

package com.python222.controller.admin;

import com.python222.entity.Post;
import com.python222.service.PostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

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

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

    @Autowired
    private PostService postService;

    /**
     * 根据条件查询自定义帖子
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/list")
    public Map list()throws Exception{
        Map resultMap = new HashMap<>();
        List postList=postService.list();
        resultMap.put("code", 0);
        resultMap.put("data", postList);
        return resultMap;
    }

    /**
     * 添加或者修改自定义帖子
     * @param post
     * @return
     */
    @RequestMapping("/save")
    public Map save(Post post){
        if(post.getId()==null){
            postService.save(post);
        }else{
            postService.updateById(post);
        }
        Map resultMap = new HashMap<>();
        resultMap.put("success", true);
        return resultMap;
    }

    /**
     * 删除自定义帖子
     * @param id
     * @return
     * @throws Exception
     */
    @RequestMapping("/delete")
    public Map delete(Integer id)throws Exception{
        Map resultMap = new HashMap<>();
        postService.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<>();
        Post post=postService.getById(id);
        resultMap.put("post", post);
        resultMap.put("success", true);
        return resultMap;
    }



}

前端postManage.html





自定义帖子管理













再新建一个savePost.html





添加或者修改自定义帖子




标题:
内容:

自定义帖子详情查看:

新建PostController类:

package com.python222.controller;

import com.python222.entity.Post;
import com.python222.service.PostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

/**
 * 自定义帖子控制器
 * @author python222小锋老师
 * @site www.python222.com
 */
@Controller
@RequestMapping("/post")
public class PostController {

    @Autowired
    private PostService postService;

    /**
     * 根据id查询自定义帖子详细信息
     * @param id
     * @return
     * @throws Exception
     */
    @RequestMapping("/{id}")
    public ModelAndView view(@PathVariable("id")Integer id)throws Exception{
        ModelAndView mav=new ModelAndView();
        Post post = postService.getById(id);
        mav.setViewName("post");
        mav.addObject("post",post);
        return mav;
    }

}

前端新建模板post.html



















    

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