vue+iview框架前端页面实现搜索

描述

项目使用的是vue+iview框架,要对从后台查到的数据进行一个对名称模糊查询的功能(结合了分页),思路是获取到表单中输入的关键字,传到后台,后台通过mybatis的example类写模糊查询

完成后的展示

在这里插入图片描述

前端代码

      <Form ref="formSearch" inline>
         <FormItem style="margin:auto;" prop="keywords">
           <Input search v-model="formSearch.keywords" placeholder="请输入名称"></Input>
         </FormItem>
         <FormItem style="margin:auto;">
           <Button type="primary" @click="goPage()">搜索</Button>
         </FormItem>
      </Form>
goPage(n) {
      n = n || 1;
      this.req.pageNo = n;
      this.loading = true;
      this.req.keywords = this.formSearch.keywords;
      this.$global.get("pool/list", this.req).then(res => {
        if (res.success) {
          this.datalist = res.data.list;
          this.total = res.data.total;
          this.loading = false;
        } else {
          this.$Message.error(res.errorMsg);
        }
      });
    }

后端代码

//Controller
	@GetMapping("/list")
	public ResponseInfo list(Integer pageNo, Integer size, String keywords) {
		return ResponseInfo.success(service.selectByPage(pageNo, size, keywords));
	}
//Service
	public PageInfo<Pool> selectByPage(Integer pageNo, Integer size, String keywords) {
		if (null == pageNo)
			pageNo = 1;
		if (null == size)
			size = 10;
		PoolExample example = new PoolExample();
		List<Integer> depIds = service.getActiveUserDepIds();
		if (depIds.size() > 0) {
			example.createCriteria().andDepIdIn(depIds);
		}
		if (keywords != null && !"".equals(keywords)) {
			keywords = "%" + keywords + "%";
			example.createCriteria().andNameLike(keywords);
		}
		PageHelper.startPage(pageNo, size);
		List<Pool> list = mapper.selectByExample(example);
		return new PageInfo<>(list);
	}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值