mybatis-plus+springboot+vue+element-ui实现分页

第一步导入依赖

<!--     分页组件   -->
        <dependency>
            <groupId>com.github.pagehelper</groupId>
            <artifactId>pagehelper</artifactId>
            <version>5.2.0</version>
        </dependency>
        <!--        mybatis-plus-->
<!-- https://mvnrepository.com/artifact/com.baomidou/mybatisplus-spring-boot-starter -->
            <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
            <version>3.2.0</version>
        </dependency>

然后导入前端element-ui组件+html代码

<!--    elementUi-->
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
    <script src="https://unpkg.com/element-ui/lib/index.js"></script>
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
<div id="app">
    <div class="layui-card-header" style="margin-top: 20px">
        <button class="layui-btn layui-btn-danger" @click="deleteSel" type="button">
            <i class="layui-icon"></i>批量删除</button>
        <button class="layui-btn" onclick="xadmin.open('添加用户','/basic/custom/creat',800,600)"><i class="layui-icon"></i>添加</button>
        <div class="layui-inline layui-show-xs-block">
            <input type="text" id="renCarPerson" name="renCarPerson" placeholder="请输入用户名" autocomplete="off" class="layui-input"></div>
        <div class="layui-inline layui-show-xs-block">
            <button class="layui-btn" @click="findByName()">
                <i class="layui-icon"></i></button>
        </div>
    </div>
    <div class="layui-card-body">
        <table class="layui-table">
            <thead>
            <tr>
                <th>
                    <input type="checkbox" name="" class="layui-unselect layui-form-checkbox" lay-skin="primary" onclick="swapCheck()">
                </th>
                <th>序号</th>
                <th>租车人</th>
                <th>客户性别</th>
                <th>联系方式</th>
                <th>销售负责人</th>
                <th>家庭住址</th>
                <th>租车车型</th>
                <th>租车时间</th>
                <th>支付金额</th>
                <th>还车时间</th>
                <th>租车状态</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            <tr v-for="item in list">
                <td>
                    <input type="checkbox" name="checkbox" class="layui-unselect layui-form-checkbox" lay-skin="primary"  :value="item.id" v-model="selectArr">
                </td>
                <td>{{ item.id}}</td>
                <td>{{ item.renCarPerson}}</td>
                <td>{{ item.cusSex}}</td>
                <td>{{ item.cusMobile}}</td>
                <td>{{item.saleId}}</td>
                <td>{{ item.cusAddress}}</td>
                <td>{{ item.rentCarType}}</td>
                <td>{{ item.rentCarTime.substring(0,16).replace("T"," ")}}</td>
                <td>{{ item.payMoney}}</td>
                <td>{{ item.returnCarTime.substring(0,16).replace("T"," ")}}</td>
                <td>{{ item.rentCarState}}</td>
                <td class="td-manage">
                    <a title="查看"  onclick="xadmin.open('添加用户','/basic/custom/edit',800,600)" href="javascript:;">
                        <i class="layui-icon"></i></a>
                    <!--                <a title="删除" οnclick="member_del(this,'要删除的id')" href="javascript:;">-->
                    <a title="删除" @click="del(item.id)" href="javascript:;">
                        <i class="layui-icon"></i></a>
                </td>
            </tr>
            </tbody>
        </table>
        </div>
        <!--   element-ui分页组件-->
         <div class="block">
             <el-pagination
                     @size-change="handleSizeChange"
                     @current-change="handleCurrentChange"
                     :current-page="this.params.page"
                     :page-sizes="[1, 2, 3, 4]"
                     :page-size="this.params.size"
                     layout="total, sizes, prev, pager, next, jumper"
                     :total="this.total">
             </el-pagination>
        </div>
    </div>
</div>	

<!---官网提供的axios在线地址-->
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script>
    var app = new Vue({
        el:"#app",
        data:{
            page:1,
            size:'',
            list:[],
            total:'',
            params: {
                page: 1,
                size: 6,
            },
        },
        mounted() {
            // 页面一加载完成就执行getData方法
            // this.getData();
            this.pagehelper();
        },
        methods:{
            //    分页
            handleSizeChange(val) {
                console.log(`每页 ${val}`);
                this.params.size = val;
                this.pagehelper();
            },
            handleCurrentChange(val) {
                console.log(`当前页: ${val}`);
                this.params.page = val;
                this.pagehelper();
            },
            pagehelper:function(){
                that = this;
                axios.get("/inventory/pagehelper/" + this.params.page + "/" + this.params.size).then((res) => {
                    console.log("分页页面")
                    console.log(res.data);
                    console.log("分页后")
                    that.list = res.data.records;
                    console.log(this.list)
                    that.total = res.data.total;
                    console.log(this.total)
                });
            }
        }

    })
</script>

后端代码

mybatis-plus配置文件

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

//mybatis-plus分页插件
@Configuration
@ConditionalOnClass(value = {PaginationInterceptor.class})
public class MybatisPlusConfig {

    @Bean
    public PaginationInterceptor paginationInterceptor() {
        PaginationInterceptor paginationInterceptor = new PaginationInterceptor();
        return paginationInterceptor;
    }
}

mapper层

public interface InventoryMapper extends BaseMapper<Inventory> {
    //分页
    public Page<Inventory> findByPageService(int pageCode, int pageSize);
}

service层

public interface InventoryService extends IService<Inventory> {
    //分页
    public Page<Inventory> findByPageService(int pageCode, int pageSize);
}

serviceImpl层


@Service
public class InventoryServiceImpl extends ServiceImpl<InventoryMapper, Inventory> implements InventoryService{
  @Resource
    InventoryMapper inventoryMapper;

    @Override
    public Page<Inventory> findByPageService(int pageCode, int pageSize) {
        //1.创建Page对象,传入两个参数:当前页和每页显示记录数
        Page<Inventory> page = new Page<Inventory>(pageCode,pageSize);
        //2.将分页查询到的所有数据封装到Page对象中
        inventoryMapper.selectPage(page,null);
        return page;
    }
}

最后controller层

    //    分页
    @RequestMapping(value = "/pagehelper/{pageCode}/{pageSize}",method = RequestMethod.GET)
    @ResponseBody
    public Page<Inventory> findByPage(@PathVariable(value = "pageCode") int pageCode, @PathVariable(value = "pageSize") int pageSize) {
        System.out.println(pageCode+"...."+pageSize);
        Page<Inventory> pageInfo = inventoryService.findByPageService(pageCode, pageSize);
//        System.out.println(pageInfo);
        return pageInfo;
    }

页面展示

在这里插入图片描述

  • 3
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
很抱歉,我无法提供具体的免费源码。但是,我可以为你提供一些指导来帮助你搭建基于Vue2、ElementSpring BootMyBatis-Plus和MySQL的商城系统。 首先,你可以按照以下步骤进行开发: 1. 设置前端项目:使用Vue CLI创建一个新的Vue项目并安装Element UI库,这将为你提供用户界面组件和样式。 2. 开发前端页面:根据商城的需求,设计和开发前端页面,包括商品列表、购物车、订单等功能。使用Element UI的组件和样式来构建用户友好的界面。 3. 创建后端项目:使用Spring Initializr创建一个新的Spring Boot项目,并添加必要的依赖,如Spring Web、MyBatis-Plus和MySQL驱动程序。 4. 配置数据库:在MySQL中创建一个数据库,并配置Spring Boot应用程序的数据库连接。使用MyBatis-Plus来简化数据库操作,包括数据表映射、CRUD操作等。 5. 开发后端接口:根据商城的需求,设计和开发后端接口,包括商品查询、购物车管理、订单处理等功能。使用Spring Boot的注解来定义RESTful API,并调用MyBatis-Plus进行数据库操作。 6. 前后端交互:通过HTTP请求将前端页面与后端接口连接起来。在Vue项目中使用Axios库来发送和接收数据,并处理响应结果。 7. 测试和部署:对商城系统进行测试,确保功能正常运行。使用适当的工具和平台,将前端和后端部署到生产环境中。 请注意,这只是一个大致的指导,具体的实现细节可能会因项目需求和个人偏好而有所不同。你需要根据自己的情况进行适当的调整和扩展。如果你在具体实现中遇到问题,可以随时向我提问,我会尽力帮助你。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值