mirror of
https://github.com/PlayEdu/PlayEdu
synced 2025-06-22 20:02:42 +08:00
分页查询
This commit is contained in:
parent
226cfe9fb2
commit
f76ac20fa9
6
pom.xml
6
pom.xml
@ -56,6 +56,12 @@
|
|||||||
<artifactId>spring-boot-starter-test</artifactId>
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.baomidou</groupId>
|
||||||
|
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||||
|
<version>3.5.3</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
19
src/main/java/xyz/playedu/api/config/MybatisPlusConfig.java
Normal file
19
src/main/java/xyz/playedu/api/config/MybatisPlusConfig.java
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
package xyz.playedu.api.config;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.DbType;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class MybatisPlusConfig {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public MybatisPlusInterceptor mybatisPlusInterceptor() {
|
||||||
|
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
|
||||||
|
interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
|
||||||
|
return interceptor;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
package xyz.playedu.api.controller.admin;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
import xyz.playedu.api.domain.AdminUser;
|
||||||
|
import xyz.playedu.api.service.impl.AdminUserServiceImpl;
|
||||||
|
import xyz.playedu.api.types.PageResult;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
public class AdminUserController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private AdminUserServiceImpl adminUserService;
|
||||||
|
|
||||||
|
@GetMapping("/admin/user/index")
|
||||||
|
public PageResult<AdminUser> List(@RequestParam("page") Integer page, @RequestParam("size") Integer size) {
|
||||||
|
PageResult<AdminUser> result = adminUserService.paginate(page, size, null);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
133
src/main/java/xyz/playedu/api/domain/AdminUser.java
Normal file
133
src/main/java/xyz/playedu/api/domain/AdminUser.java
Normal file
@ -0,0 +1,133 @@
|
|||||||
|
package xyz.playedu.api.domain;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Date;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @TableName admin_users
|
||||||
|
*/
|
||||||
|
@TableName(value ="admin_users")
|
||||||
|
@Data
|
||||||
|
public class AdminUser implements Serializable {
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@TableId(type = IdType.AUTO)
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 姓名
|
||||||
|
*/
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 邮箱
|
||||||
|
*/
|
||||||
|
private String email;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 密码
|
||||||
|
*/
|
||||||
|
private String password;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 登录IP
|
||||||
|
*/
|
||||||
|
private String loginIp;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 登录时间
|
||||||
|
*/
|
||||||
|
private Date loginAt;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 1禁止登录,0否
|
||||||
|
*/
|
||||||
|
private Integer isBanLogin;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 登录次数
|
||||||
|
*/
|
||||||
|
private Integer loginTimes;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private Date createdAt;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private Date updatedAt;
|
||||||
|
|
||||||
|
@TableField(exist = false)
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object that) {
|
||||||
|
if (this == that) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (that == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (getClass() != that.getClass()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
AdminUser other = (AdminUser) that;
|
||||||
|
return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId()))
|
||||||
|
&& (this.getName() == null ? other.getName() == null : this.getName().equals(other.getName()))
|
||||||
|
&& (this.getEmail() == null ? other.getEmail() == null : this.getEmail().equals(other.getEmail()))
|
||||||
|
&& (this.getPassword() == null ? other.getPassword() == null : this.getPassword().equals(other.getPassword()))
|
||||||
|
&& (this.getLoginIp() == null ? other.getLoginIp() == null : this.getLoginIp().equals(other.getLoginIp()))
|
||||||
|
&& (this.getLoginAt() == null ? other.getLoginAt() == null : this.getLoginAt().equals(other.getLoginAt()))
|
||||||
|
&& (this.getIsBanLogin() == null ? other.getIsBanLogin() == null : this.getIsBanLogin().equals(other.getIsBanLogin()))
|
||||||
|
&& (this.getLoginTimes() == null ? other.getLoginTimes() == null : this.getLoginTimes().equals(other.getLoginTimes()))
|
||||||
|
&& (this.getCreatedAt() == null ? other.getCreatedAt() == null : this.getCreatedAt().equals(other.getCreatedAt()))
|
||||||
|
&& (this.getUpdatedAt() == null ? other.getUpdatedAt() == null : this.getUpdatedAt().equals(other.getUpdatedAt()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
final int prime = 31;
|
||||||
|
int result = 1;
|
||||||
|
result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
|
||||||
|
result = prime * result + ((getName() == null) ? 0 : getName().hashCode());
|
||||||
|
result = prime * result + ((getEmail() == null) ? 0 : getEmail().hashCode());
|
||||||
|
result = prime * result + ((getPassword() == null) ? 0 : getPassword().hashCode());
|
||||||
|
result = prime * result + ((getLoginIp() == null) ? 0 : getLoginIp().hashCode());
|
||||||
|
result = prime * result + ((getLoginAt() == null) ? 0 : getLoginAt().hashCode());
|
||||||
|
result = prime * result + ((getIsBanLogin() == null) ? 0 : getIsBanLogin().hashCode());
|
||||||
|
result = prime * result + ((getLoginTimes() == null) ? 0 : getLoginTimes().hashCode());
|
||||||
|
result = prime * result + ((getCreatedAt() == null) ? 0 : getCreatedAt().hashCode());
|
||||||
|
result = prime * result + ((getUpdatedAt() == null) ? 0 : getUpdatedAt().hashCode());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
sb.append(getClass().getSimpleName());
|
||||||
|
sb.append(" [");
|
||||||
|
sb.append("Hash = ").append(hashCode());
|
||||||
|
sb.append(", id=").append(id);
|
||||||
|
sb.append(", name=").append(name);
|
||||||
|
sb.append(", email=").append(email);
|
||||||
|
sb.append(", password=").append(password);
|
||||||
|
sb.append(", loginIp=").append(loginIp);
|
||||||
|
sb.append(", loginAt=").append(loginAt);
|
||||||
|
sb.append(", isBanLogin=").append(isBanLogin);
|
||||||
|
sb.append(", loginTimes=").append(loginTimes);
|
||||||
|
sb.append(", createdAt=").append(createdAt);
|
||||||
|
sb.append(", updatedAt=").append(updatedAt);
|
||||||
|
sb.append(", serialVersionUID=").append(serialVersionUID);
|
||||||
|
sb.append("]");
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
}
|
20
src/main/java/xyz/playedu/api/mapper/AdminUserMapper.java
Normal file
20
src/main/java/xyz/playedu/api/mapper/AdminUserMapper.java
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
package xyz.playedu.api.mapper;
|
||||||
|
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import xyz.playedu.api.domain.AdminUser;
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author tengteng
|
||||||
|
* @description 针对表【admin_users】的数据库操作Mapper
|
||||||
|
* @createDate 2023-01-30 16:22:00
|
||||||
|
* @Entity xyz.playedu.api.domain.AdminUser
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface AdminUserMapper extends BaseMapper<AdminUser> {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
13
src/main/java/xyz/playedu/api/service/AdminUserService.java
Normal file
13
src/main/java/xyz/playedu/api/service/AdminUserService.java
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
package xyz.playedu.api.service;
|
||||||
|
|
||||||
|
import xyz.playedu.api.domain.AdminUser;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author tengteng
|
||||||
|
* @description 针对表【admin_users】的数据库操作Service
|
||||||
|
* @createDate 2023-01-30 16:22:00
|
||||||
|
*/
|
||||||
|
public interface AdminUserService extends IService<AdminUser> {
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,36 @@
|
|||||||
|
package xyz.playedu.api.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||||
|
import xyz.playedu.api.domain.AdminUser;
|
||||||
|
import xyz.playedu.api.service.AdminUserService;
|
||||||
|
import xyz.playedu.api.mapper.AdminUserMapper;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import xyz.playedu.api.types.PageResult;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author tengteng
|
||||||
|
* @description 针对表【admin_users】的数据库操作Service实现
|
||||||
|
* @createDate 2023-01-30 16:22:00
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class AdminUserServiceImpl extends ServiceImpl<AdminUserMapper, AdminUser> implements AdminUserService {
|
||||||
|
|
||||||
|
public PageResult<AdminUser> paginate(int page, int size, Wrapper<AdminUser> queryWrapper) {
|
||||||
|
IPage<AdminUser> userPage = new Page<>(page, size);
|
||||||
|
userPage = this.getBaseMapper().selectPage(userPage, queryWrapper);
|
||||||
|
|
||||||
|
PageResult<AdminUser> pageResult = new PageResult<>();
|
||||||
|
pageResult.setData(userPage.getRecords());
|
||||||
|
pageResult.setTotal(userPage.getTotal());
|
||||||
|
|
||||||
|
return pageResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
26
src/main/java/xyz/playedu/api/types/PageResult.java
Normal file
26
src/main/java/xyz/playedu/api/types/PageResult.java
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
package xyz.playedu.api.types;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class PageResult<T> {
|
||||||
|
|
||||||
|
private List<T> data;
|
||||||
|
|
||||||
|
private Long total;
|
||||||
|
|
||||||
|
public List<T> getData() {
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setData(List<T> data) {
|
||||||
|
this.data = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getTotal() {
|
||||||
|
return total;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTotal(Long total) {
|
||||||
|
this.total = total;
|
||||||
|
}
|
||||||
|
}
|
@ -2,3 +2,6 @@ spring.profiles.active=dev
|
|||||||
|
|
||||||
#mybatis
|
#mybatis
|
||||||
mybatis.mapper-locations=classpath:mapper/*.xml
|
mybatis.mapper-locations=classpath:mapper/*.xml
|
||||||
|
|
||||||
|
#mybatis-plus
|
||||||
|
mybatis-plus.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl
|
26
src/main/resources/mapper/AdminUserMapper.xml
Normal file
26
src/main/resources/mapper/AdminUserMapper.xml
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE mapper
|
||||||
|
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="xyz.playedu.api.mapper.AdminUserMapper">
|
||||||
|
|
||||||
|
<resultMap id="BaseResultMap" type="xyz.playedu.api.domain.AdminUser">
|
||||||
|
<id property="id" column="id" jdbcType="INTEGER"/>
|
||||||
|
<result property="name" column="name" jdbcType="VARCHAR"/>
|
||||||
|
<result property="email" column="email" jdbcType="VARCHAR"/>
|
||||||
|
<result property="password" column="password" jdbcType="VARCHAR"/>
|
||||||
|
<result property="loginIp" column="login_ip" jdbcType="VARCHAR"/>
|
||||||
|
<result property="loginAt" column="login_at" jdbcType="TIMESTAMP"/>
|
||||||
|
<result property="isBanLogin" column="is_ban_login" jdbcType="TINYINT"/>
|
||||||
|
<result property="loginTimes" column="login_times" jdbcType="INTEGER"/>
|
||||||
|
<result property="createdAt" column="created_at" jdbcType="TIMESTAMP"/>
|
||||||
|
<result property="updatedAt" column="updated_at" jdbcType="TIMESTAMP"/>
|
||||||
|
</resultMap>
|
||||||
|
|
||||||
|
<sql id="Base_Column_List">
|
||||||
|
id,name,email,
|
||||||
|
password,login_ip,login_at,
|
||||||
|
is_ban_login,login_times,created_at,
|
||||||
|
updated_at
|
||||||
|
</sql>
|
||||||
|
</mapper>
|
Loading…
x
Reference in New Issue
Block a user