package com.gong.springbootvue.controller;
import com.gong.springbootvue.entity.User;
com.gong.springbootvue.repository.UserRepository;
org.springframework.beans.factory.annotation.Autowired;
org.springframework.data.domain.Page;
org.springframework.data.domain.PageRequest;
org.springframework.stereotype.Controller;
org.springframework.web.bind.annotation.PathVariable;
org.springframework.web.bind.annotation.RequestMapping;
org.springframework.web.bind.annotation.ResponseBody;
java.util.List;
@Controller
@RequestMapping("/user")
public class UserController {
@Autowired
UserRepository userRepository;
@ResponseBody
@RequestMapping("/findAll/{page}/{size}")
public Page<User> getAll(@PathVariable("page") Integer page,@PathVariable("size") Integer size) {
System.out.println(page);
System.out.println(size);
PageRequest pageRequest = PageRequest.of(page,size);
return userRepository.findAll(pageRequest);
}
}
<template>
div>
el-table :data="tableData"
border
style="width: 100%">
el-table-column fixed
prop="id"
label="编号"
width="150"</el-table-columnprop="username"="姓名"="120"="age"="年龄"="gender"="性别"="80"="email"="邮箱"="160 "="hobby"="爱好"="introduce"="介绍"="140"fixed="right"="操作">
template slot-scope="scope">
el-button @click="handleClick(scope.row)"
type="text"
size="small">查看el-buttontype>编辑el-tableel-pagination background
layout="prev,pager,next"
:page-size="pageSize"
:total="total"
@current-change="page"el-pagination>
script>
export default {
methods: {
handleClick (row) {
console.log(row);
},page (currentPage) {
const that = this;
axios.get('http://localhost:8181/user/findAll/' + (currentPage - 1) + '/3')
.then(function (response) {
console.log(response);
that.tableData = response.data.content;
that.pageSize = response.data.size;
that.total = response.data.totalElements;
})
},},data () {
return {
pageSize: 0,total: 0,tableData: [],}
},created () {
const that = this;
axios.get('http://localhost:8181/user/findAll/0/3')
.then(function (response) {
//console.log(response);
that.tableData = response.data.content;
that.pageSize = response.data.size;
that.total = response.data.totalElements;
})
},}
>