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/请求获取第一页数据;

/**
 * 首页
 *
 * @return
 */
@RequestMapping("/")
public ModelAndView index() {
    PageBean pageBean = new PageBean(1, 20);
    System.out.println("首页");
    ModelAndView mav = new ModelAndView();
    Page
articlePage = articleService.page(new Page<>(pageBean.getPage(), pageBean.getPageSize()), new QueryWrapper
().orderByDesc("publish_date")); mav.addObject("articleList", articlePage.getRecords()); mav.setViewName("index"); return mav; }

网页上 显示数据:

帖子随机小图标,映射路径:

randomImagesFilePath: D:\\randomImages\\
@Value("${randomImagesFilePath}")
private String randomImagesFilePath;
registry.addResourceHandler("/randomImages/**").addResourceLocations("file:"+randomImagesFilePath);  // 随机头像图片映射

分页实现:

mav.addObject("pageCode", PageUtil.genPagination("/article/list", articlePage.getTotal(), 1, pageBean.getPageSize(), ""));
package com.python222.controller;

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.PageUtil;
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;

/**
 * 帖子Controller控制器
 * @author python222小锋老师
 * @site www.python222.com
 */
@Controller
@RequestMapping("/article")
public class ArticleController {

    @Autowired
    private ArticleService articleService;

    /**
     * 分页查询帖子
     * @return
     */
    @RequestMapping("/list/{page}")
    public ModelAndView list(@PathVariable(value = "page",required = false)Integer page){
        PageBean pageBean=new PageBean(page,20);
        ModelAndView mav=new ModelAndView();
        Page
articlePage = articleService.page(new Page<>(pageBean.getPage(), pageBean.getPageSize()), new QueryWrapper
().eq("status",2).orderByDesc("publish_date")); mav.addObject("articleList",articlePage.getRecords()); mav.addObject("pageCode", PageUtil.genPagination("/article/list",articlePage.getTotal(),page,pageBean.getPageSize(),"")); mav.setViewName("index"); return mav; } }

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