angularjs分页

后台 

                                                

<!--分页需要的依赖-->

<!-- 分页 -->

<dependency>

<groupId>com.github.pagehelper</groupId>

<artifactId>pagehelper</artifactId>

<version>4.0.0</version>

</dependency>



在SqlMapConfig.xml中配置

<!-- 配置分页插件 -->
<plugins>
<plugin interceptor="com.github.pagehelper.PageHelper">
<!-- 设置数据库类型 Oracle,Mysql,MariaDB,SQLite,Hsqldb,PostgreSQL六种数据库-->
<property name="dialect" value="mysql"/>
</plugin>
</plugins>


在controller层


@RequestMapping(value="selectAll",method=RequestMethod.POST)
@ResponseBody
public  PageInfo<ShoppingCar>  selectAll(String pageNo, String pageSize,String name){
//初始化数值
        int num = 1;
        int size = 5;


        if(pageNo != null && !"".equals(pageNo)) {
            num = Integer.parseInt(pageNo);
        }
        if (pageSize != null && !"".equals(pageSize)) {
            size = Integer.parseInt(pageSize);
        }
        //开始分页
        PageHelper.startPage(num,size);
        if (name==null) {
         //查询数据库信息
    List<ShoppingCar> list = shoppingCarService.selectAll();
    //将信息放入PageInfo进行分页
            PageInfo<ShoppingCar> pageInfo = new PageInfo<ShoppingCar>(list);
    return pageInfo;
}else{
List<ShoppingCar> list = shoppingCarService.selectLikeName(name);
    //将信息放入PageInfo进行分页
            PageInfo<ShoppingCar> pageInfo = new PageInfo<ShoppingCar>(list);
    return pageInfo;
}
      
}


                                      前台用angularjs填充页面

                                         <script>
                        var app = angular.module('myApp', []);
app.controller('myController', function($scope, $http) {
 $http.post("http://localhost:8080/ShoppingCar/selectAll")
 .success(function (response) {
 $scope.data = response.list;
     $scope.pageHelper= response;
 
 });



$scope.head = function() {
   var firstPage =$scope.pageHelper.firstPage;
var pageSize = $scope.pageHelper.pageSize
  $http.post("http://localhost:8080/ShoppingCar/selectAll?pageNo="+firstPage+"&pageSize="+pageSize)
 .success(function (response) {
 $scope.data = response.list;
     $scope.pageHelper= response;
 
 });
   };
   
    $scope.last = function() {
   var lastPage =$scope.pageHelper.lastPage;
var pageSize = $scope.pageHelper.pageSize
  $http.post("http://localhost:8080/ShoppingCar/selectAll?pageNo="+lastPage+"&pageSize="+pageSize)
 .success(function (response) {
 $scope.data = response.list;
     $scope.pageHelper= response;
 });
   };
    $scope.shang = function() {
   var prePage =$scope.pageHelper.prePage;
var pageSize = $scope.pageHelper.pageSize
  $http.post("http://localhost:8080/ShoppingCar/selectAll?pageNo="+prePage+"&pageSize="+pageSize)
 .success(function (response) {
 $scope.data = response.list;
     $scope.pageHelper= response;
 });
   };
     $scope.next = function() {
   var nextPage =$scope.pageHelper.nextPage;
var pageSize = $scope.pageHelper.pageSize
  $http.post("http://localhost:8080/ShoppingCar/selectAll?pageNo="+nextPage+"&pageSize="+pageSize)
 .success(function (response) {
 $scope.data = response.list;
     $scope.pageHelper= response;
 });
   };

              });
</script>





                                      <label class=" control-label">共<span>{{pageHelper.total}}条记录当前显示</span><span>现在显示第{{pageHelper.pageNum}}页</span></label>
        <button class="btn btn-default" ng-click="head()">首页</button>
<label ng-if="pageHelper.isFirstPage == true">
       <button class="btn btn-default" ng-click="head()">上一页</button>
   </label>
   <label ng-if="pageHelper.isFirstPage == false">
       <button class="btn btn-default" ng-click="shang()">上一页</button>
   </label>


<label ng-if="pageHelper.isLastPage == true">
<button class="btn btn-default" ng-click="last()">下一页</button>
</label>
  <label ng-if="pageHelper.isLastPage == false">
      <button class="btn btn-default" ng-click="next()">下一页</button>
  </label>
<button class="btn btn-default" ng-click="last()">尾页</button>



          



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值