@GetMapping public Result> findPage( @RequestParam(defaultValue = "1") Integer pageNum ,@RequestParam(defaultValue = "10") Integer pageSize ,@RequestParam(defaultValue = "") String search){ LambdaQueryWrapper然后我们在网页上可以看到这样的现象: 然后我们接下来在前端接收这些值:wrapper = Wrappers. lambdaQuery(); if (StrUtil.isNotBlank(search)){ wrapper.like(User::getNickName,search); } Page userPage = userMapper.selectPage(new Page<>(pageNum, pageSize),wrapper); return Result.success(userPage); }
// 加载数据库数据进行渲染 load(){ request.get("/user",{ params:{ pageNum:this.currentPage, pageSize:this.pageSize, search:this.search } }).then(res =>{ console.log(res) this.tableData = res.data.records this.total = res.data.total }) },然后我们在初始的时候加载: 接下来就是增删改查的前后端代码: 后端:
package com.example.demo.controller; import cn.hutool.core.util.StrUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.example.demo.common.Result; import com.example.demo.entity.User; import com.example.demo.mapper.UserMapper; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; @RestController @RequestMapping("/user") public class UserController { @Resource UserMapper userMapper; @PostMapping public Result> save(@RequestBody User user){ if (user.getPassword() == null){ user.setPassword("123456"); } userMapper.insert(user); return Result.success(); } @GetMapping public Result> findPage( @RequestParam(defaultValue = "1") Integer pageNum ,@RequestParam(defaultValue = "10") Integer pageSize ,@RequestParam(defaultValue = "") String search){ LambdaQueryWrapper前端:wrapper = Wrappers. lambdaQuery(); if (StrUtil.isNotBlank(search)){ wrapper.like(User::getNickName,search); } Page userPage = userMapper.selectPage(new Page<>(pageNum, pageSize),wrapper); return Result.success(userPage); } @PutMapping public Result> update(@RequestBody User user){ userMapper.updateById(user); return Result.success(); } @DeleteMapping("/{id}") public Result> delete(@PathVariable Long id){ userMapper.deleteById(id); return Result.success(); } }
新增 导入 导出 欢迎分享,转载请注明来源:内存溢出
评论列表(0条)