springboot+mybatisplus+layui+restful实现无刷新分页,带有多条件模糊查询

精选30+云产品,助力企业轻松上云!>>> hot3.png

1.之前在做分页的时候,都是采用mybatis+papehelper发送网络请求,需要写大量的分页代码,后台还需要写分页的工具类。这里我才用一种全新的restful风格+layui的分页形式,不仅不用写分页工具类,不用写大量请求,不用写前端分页,还不用发送链接请求!!!

2.使用教学:首先在layui官网拿下layui的js+css文件,我们以动态数据表为例。

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>table模块快速使用</title>
  <link rel="stylesheet" href="/layui/css/layui.css" media="all">
</head>
<body>
 
<table id="demo" lay-filter="test"></table>
 
<script src="/layui/layui.js"></script>
<script>
layui.use('table', function(){
  var table = layui.table;
  
  //第一个实例
  table.render({
    elem: '#demo'
    ,height: 312
    ,url: '/demo/table/user/' //数据接口
    ,page: true //开启分页
    ,cols: [[ //表头
      {field: 'id', title: 'ID', width:80, sort: true, fixed: 'left'}
      ,{field: 'username', title: '用户名', width:80}
      ,{field: 'sex', title: '性别', width:80, sort: true}
      ,{field: 'city', title: '城市', width:80} 
      ,{field: 'sign', title: '签名', width: 177}
      ,{field: 'experience', title: '积分', width: 80, sort: true}
      ,{field: 'score', title: '评分', width: 80, sort: true}
      ,{field: 'classify', title: '职业', width: 80}
      ,{field: 'wealth', title: '财富', width: 135, sort: true}
    ]]
  });
  
});
</script>
</body>
</html>

3.MybatisplusConfig.java分页配置类

package com.wang.springboot.sys.config;

import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;

/**
 * @Author: 王一宁
 * @Date: 2019/11/23 19:16
 * 分页插件
 */
@Configuration
@ConditionalOnClass(value= {PaginationInterceptor.class})
public class MybatisPlusConfig {
    @Bean
    public PaginationInterceptor  paginationInterceptor() {
        return new PaginationInterceptor();
    }
}

4.News.java实体类

package com.wang.springboot.sys.domain;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.util.Date;

/**
 * @author 王一宁
 * @date 2020/3/19 9:17
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("sys_news")
@ToString
public class News implements Serializable {
    private static final long serialVersionUID=1L;

    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;

    private String title;

    private Date newstime;

    private String content;
}

5.NewsVo.java 用来补充封装中间数据

package com.wang.springboot.sys.vo;

import com.wang.springboot.sys.domain.News;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * @author 王一宁
 * @date 2020/3/19 9:24
 */
@Data
@EqualsAndHashCode(callSuper = false)
public class NewsVo extends News {

    private Integer page=1;
    private Integer limit=10;
	
	@DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date startDate;

    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date endDate;
}

6.DataGridView.java 用来返回json数据的实体

package com.wang.springboot.sys.common;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author 王一宁
 * @date 2020/3/17 13:07
 * json数据实体
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class DataGridView {
    private Integer code = 0;
    private String msg = "";
    private Long count = 0L;
    private Object data;

    public DataGridView(Long count, Object data) {
        this.count = count;
        this.data = data;
    }

    public DataGridView(Object data) {
        this.data = data;
    }
}

7.NewsController.java

package com.wang.springboot.sys.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wang.springboot.sys.common.DataGridView;
import com.wang.springboot.sys.common.ResultObj;
import com.wang.springboot.sys.domain.Dept;
import com.wang.springboot.sys.domain.News;
import com.wang.springboot.sys.service.NewsService;
import com.wang.springboot.sys.vo.NewsVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 王一宁
 * @date 2020/3/19 9:25
 */
@RestController
@RequestMapping("news")
public class NewsController {

    @Autowired
    private NewsService newsService;

    @RequestMapping("listNews")
    public DataGridView listNews(NewsVo newsVo){
        //分页显示
        IPage<News> page = new Page<>(newsVo.getPage(),newsVo.getLimit());
        //模糊查询
        QueryWrapper<News> queryWrapper = new QueryWrapper<>();
        //查询时间的条件 下面为一个时间区间,也可以再添加别的条件
        queryWrapper.ge(newsVo.getStartDate()!=null,"newstime",newsVo.getStartDate());
        queryWrapper.le(newsVo.getEndDate()!=null,"newstime",newsVo.getEndDate());
        //按照时间倒叙
        queryWrapper.orderByDesc("newstime");
        //查询数据
        newsService.page(page,queryWrapper);
        return new DataGridView(page.getTotal(),page.getRecords());
    }

}

8.NewsService.java

/**
 * @author 王一宁
 * @date 2020/3/19 9:31
 */
public interface NewsService extends IService<News> {
}

9.NewsServiceImpl.java

/**
 * @author 王一宁
 * @date 2020/3/19 9:31
 */
@Service
@Transactional
public class NewsServiceImpl extends ServiceImpl<NewsMapper, News> implements NewsService {
}

9.NewsMapper.java

/**
 * @author 王一宁
 * @date 2020/3/19 9:34
 */
@Mapper
public interface NewsMapper extends BaseMapper<News> {
}

10.前端测试页面,我用的layui的动态数据表

	<link rel="stylesheet" th:href="@{/resources/layui/css/layui.css}" media="all" />	
<!--表格容器-->
	<table class="layui-table" lay-data="{height:315, url:'/news/listNews', page:true, id:'test'}" lay-filter="test">
		<thead>
		<tr>
			<th lay-data="{field:'id', width:80, sort: true}">ID</th>
			<th lay-data="{field:'title', width:300}">标题</th>
			<th lay-data="{field:'content', width:700, sort: true}">内容</th>
		</tr>
		</thead>
	</table>
	<script type="text/javascript" th:src="@{/resources/layui/layui.js}"></script>

11.比较全面的页面,如【表】【搜索框】【时间框】【下拉框追加数据】

<!DOCTYPE html>
<html xmlns:th="http://www.w3.org/1999/xhtml">
<head>
	<meta charset="utf-8">
	<title>首页--工作台</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
	<link rel="stylesheet" th:href="@{/resources/layui/css/layui.css}" media="all" />
	<link rel="stylesheet" th:href="@{/resources/css/public.css}" media="all" />
</head>
<body class="childrenBody">

	<!--表单开始-->
	<form class="layui-form" id="searchFrm" method="post" action="">
		<!--搜索框-->

		<div class="layui-inline">
			<label class="layui-form-label">按开始日期</label>
			<div class="layui-input-inline">
				<input type="text" name="startDate" id="startDate"  placeholder="yyyy-MM-dd"  class="layui-input">
			</div>
		</div>
		<div class="layui-inline">
			<label class="layui-form-label">按结束日期</label>
			<div class="layui-input-inline">
				<input type="text" name="endDate" id="endDate"  placeholder="yyyy-MM-dd"  class="layui-input">
			</div>
		</div>

		<div class="layui-form-item">
			<div class="layui-inline">
				<label class="layui-form-label">单选下拉框</label>
				<div class="layui-input-inline">
					<select name="typeid" id="search_typeid">
						<option value="1">请选择</option>
					</select>
				</div>
			</div>
		</div>

		<div class="layui-form-item">
			<div class="layui-input-block">
				<button type="button" class="layui-btn" lay-submit="" lay-filter="doSearch">查询</button>
				<button type="reset" class="layui-btn layui-btn-primary">重置</button>
				<button type="button" class="layui-btn layui-btn-primary">添加</button>
			</div>
		</div>
	</form>

	<!--表格容器-->

	<table id="demo" lay-filter="test"></table>

	<!--表格容器结束-->


	<script type="text/javascript" th:src="@{/resources/layui/layui.js}"></script>

	<script type="text/javascript">
		//加载layui
		layui.use(['form','element','layer','jquery','table'],function(){

			var form = layui.form, $ = layui.jquery;
			var table = layui.table;

			//第一个实例
			var tableIns = table.render({
				elem: '#demo'
				,height: 312
				,url: '/news/listNews' //数据接口
				,page: true //开启分页
				,cols: [ [ //表头
					{field: 'id', title: 'ID', width:80, sort: true, fixed: 'left'}
					,{field: 'title', title: '用户名', width:80}
					,{field: 'content', title: '性别', width:80, sort: true}
				] ]
			});


			//获取到 初始化下拉查询列表的内容【这一部分的后台我没有展示】
			$.get("/type/loadAllType",function (objs) {
				var types = objs.data;
				var search_typeid = $("#search_typeid");
				$.each(types,function (index,item) {
					//追加数据
					search_typeid.append("<potion value="+item.id+">"+item.name+"</potion>");
				});
				//重新渲染
				form.render("select");
			});

			//模糊查询
			form.on("submit(doSearch)",function (data) {
				//ajax方式发送数据
				$.post("/news/listNews",data.field,function () {
					tableIns.reload({
						url:'/news/listNews',
						where:data.field
					});
				return false;
				});
			});
		});

	</script>
</body>
</html>
  • 3
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
图书管理系统是一个常见的项目,下面是使用 SpringBoot + MyBatisPlus + Restful + Vue + Jquery + Axios 的图书管理系统的简单介绍。 1. 项目概述 该项目是一个图书管理系统,主要功能包括: - 图书的增删改查 - 图书分类的增删改查 - 图书借阅的管理 2. 技术栈 - 后端:SpringBoot + MyBatisPlus + Restful - 前端:Vue + Jquery + Axios 3. 功能模块 - 登录模块:用户登录、退出登录 - 图书管理模块:图书查询、添加、修改、删除 - 图书分类模块:图书分类查询、添加、修改、删除 - 借阅管理模块:借阅记录查询、添加、修改、删除 4. 项目结构 - backend:后端代码 - src/main/java/com/example/demo:Java 代码 - src/main/resources:配置文件和静态资源 - frontend:前端代码 - src:Vue 代码 5. 实现步骤 - 使用 Spring Initializr 创建一个 SpringBoot 项目 - 引入 MyBatisPlus、Druid 数据库连接池、Lombok 等依赖 - 创建数据库表,使用 MyBatisPlus 自动生成实体类和 Mapper 接口 - 创建 Restful API,提供图书、图书分类、借阅记录的增删改查接口 - 使用 Vue、Jquery、Axios 等前端技术实现前端界面,调用后端提供的接口实现相应功能 6. 总结 该项目基于 SpringBoot + MyBatisPlus + Restful + Vue + Jquery + Axios 技术栈,实现了一个简单的图书管理系统。通过该项目,可以学习到如何使用 SpringBoot 进行开发,如何使用 MyBatisPlus 简化数据库操作,以及如何使用 Vue、Jquery、Axios 等前端技术实现前端界面。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Coding路人王

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值