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、后端方法实现:
@Overridepublic PageResult search(Integer pageNo, Integer pageSize, Brand brand) {//构建查询的exapleBrandExample 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查询到的值加入exampleexample.or(criteria2);//把criteria2查询到的值加入example//分页显示所有品牌名称或者首字母出现过输入关键字的品牌PageHelper.startPage(pageNo,pageSize);Page<Brand> page= (Page<Brand>) brandMapper.selectByExample(example);return new PageResult(page.getTotal(),page.getResult());}
实现效果: