BrandExample.Criteria方法 实现搜索框输入关键字模糊查询

1、前端:

搜索框:

			<div class="has-feedback">
                关键字查询:<input ng-model="searchEntity.name">
				<button type="button" class="btn btn-default" ng-click="search()">查询</button>
			</div>

方法实现:

前端:brandService层:
    //分页查询方法
        this.search = function (pageNo,pageSize,entity) {
        return $http.post("/brand/search?pageNo=" + pageNo + "&pageSize=" + pageSize, entity);
    }


   前端controller层:
   
    $scope.search=function() {
        brandService.search($scope.paginationConf.currentPage,$scope.paginationConf.itemsPerPage,  $scope.searchEntity)
            .success(function (data) {
        $scope.list = data.rows;
        $scope.paginationConf.totalItems = data.total;
    })
    }

2、后端方法实现:

    @Override
    public PageResult search(Integer pageNo, Integer pageSize, Brand brand) {

        //构建查询的exaple
        BrandExample example=new BrandExample();
        //构建查询的条件
        Criteria criteria1 = example.createCriteria();
        Criteria criteria2 = example.createCriteria();
        if(brand!=null){
           criteria1.andNameLike("%"+brand.getName()+"%");//查询品牌名称是否包含前端输入的brand.getName()值
           criteria2.andFirstCharLike("%"+brand.getName()+"%");//查询品牌首字母是否包含前端输入的brand.getName()值
        }
        example.or(criteria1);//把criteria1查询到的值加入example
        example.or(criteria2);//把criteria2查询到的值加入example
        //分页显示所有品牌名称或者首字母出现过输入关键字的品牌
        PageHelper.startPage(pageNo,pageSize);
        Page<Brand> page= (Page<Brand>) brandMapper.selectByExample(example);
        return new PageResult(page.getTotal(),page.getResult());

    }


实现效果:
在这里插入图片描述

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值