沃梦达 / IT编程 / 前端开发 / 正文

vue+springboot实现分页

方法1、//Java部分的主要实现的业务逻辑public MapString, Object getTeacherFrontList(PageEduTeacher pageTeacher) {QueryWrapperEduTeacher wrapper = new QueryWrapper();wrapper.orderByDesc(id);Pag...

方法1、

   	//Java部分的主要实现的业务逻辑
    public Map<String, Object> getTeacherFrontList(Page<EduTeacher> pageTeacher) {
        QueryWrapper<EduTeacher> wrapper = new QueryWrapper<>();
        wrapper.orderByDesc("id");
        Page<EduTeacher> teacherPage = baseMapper.selectPage(pageTeacher, wrapper);
        List<EduTeacher> teacherRecords = teacherPage.getRecords();
        long total = teacherPage.getTotal();
        long current = teacherPage.getCurrent();
        long pages = teacherPage.getPages();
        boolean next = teacherPage.hasNext();
        long size = teacherPage.getSize();
        boolean previous = teacherPage.hasPrevious();
        Map<String, Object> teacherMap = new HashMap<>();
        teacherMap.put("items",teacherRecords);
        teacherMap.put("total",total);
        teacherMap.put("current",current);
        teacherMap.put("size",size);
        teacherMap.put("hasNext",next);
        teacherMap.put("hasPrevious",previous);
        teacherMap.put("pages",pages);
        return teacherMap;
    }
 //JS部分的主要实现业务逻辑
  <div>
          <div class="paging">
            <!-- undisable这个class是否存在,取决于数据属性hasPrevious -->
            <a
              :class="{undisable: !teacherData.hasPrevious}"
              href="#"
              title="6aaW6aG1"
              @click.prevent="gotoPage(1)">首</a>
            <a
              :class="{undisable: !teacherData.hasPrevious}"
              href="#"
              title="5YmN5LiA6aG1"
              @click.prevent="gotoPage(teacherData.current-1)">&lt;</a>
            <a
              v-for="page in teacherData.pages"
              :key="page"
              :class="{current: teacherData.current == page, undisable: teacherData.current == page}"
              :title="J+esrA=="+page+'页'"
              href="#"
              @click.prevent="gotoPage(page)">{{ page }}</a>
            <a
              :class="{undisable: !teacherData.hasNext}"
              href="#"
              title="5ZCO5LiA6aG1"
              @click.prevent="gotoPage(teacherData.current+1)">&gt;</a>
            <a
              :class="{undisable: !teacherData.hasNext}"
              href="#"
              title="5pyr6aG1"
              @click.prevent="gotoPage(teacherData.pages)">末</a>
            <div class="clear"/>
          </div>
        </div>



		<script>
		export default {
		    asyncData({ params, error }) {
		    return teacher.getTeacherList(1, 8).then(response => {
		      console.log("teacher数据",response.data.data);
		      return { teacherData: response.data.data }
		    });
		  },
		    methods:{
		      gotoPage(page){
		        teacher.getTeacherList(page, 8)
		        .then(response => {
		          this.teacherData = response.data.data
		        })
		      }
		    }
		};
		</script>


//请求的js部分
 getTeacherList(current,limit) { //查询讲师列表
    return request({
      url: `/eduservice/teacherfront/getTeacherFrontList/${current}/${limit}`,
      method: 'get'
    })
  },

本文标题为:vue+springboot实现分页