1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > BrandExample.Criteria方法 实现搜索框输入关键字模糊查询

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

时间:2022-11-26 02:24:05

相关推荐

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、后端方法实现:

@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());}

实现效果:

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。