From f76ac20fa9e52a3df39c8549bfd654cffbbeac45 Mon Sep 17 00:00:00 2001 From: none Date: Mon, 30 Jan 2023 16:49:17 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=86=E9=A1=B5=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 6 + .../playedu/api/config/MybatisPlusConfig.java | 19 +++ .../controller/admin/AdminUserController.java | 23 +++ .../xyz/playedu/api/domain/AdminUser.java | 133 ++++++++++++++++++ .../playedu/api/mapper/AdminUserMapper.java | 20 +++ .../playedu/api/service/AdminUserService.java | 13 ++ .../service/impl/AdminUserServiceImpl.java | 36 +++++ .../xyz/playedu/api/types/PageResult.java | 26 ++++ src/main/resources/application.properties | 5 +- src/main/resources/mapper/AdminUserMapper.xml | 26 ++++ 10 files changed, 306 insertions(+), 1 deletion(-) create mode 100644 src/main/java/xyz/playedu/api/config/MybatisPlusConfig.java create mode 100644 src/main/java/xyz/playedu/api/controller/admin/AdminUserController.java create mode 100644 src/main/java/xyz/playedu/api/domain/AdminUser.java create mode 100644 src/main/java/xyz/playedu/api/mapper/AdminUserMapper.java create mode 100644 src/main/java/xyz/playedu/api/service/AdminUserService.java create mode 100644 src/main/java/xyz/playedu/api/service/impl/AdminUserServiceImpl.java create mode 100644 src/main/java/xyz/playedu/api/types/PageResult.java create mode 100644 src/main/resources/mapper/AdminUserMapper.xml diff --git a/pom.xml b/pom.xml index bb7c9e0..2774ce2 100644 --- a/pom.xml +++ b/pom.xml @@ -56,6 +56,12 @@ spring-boot-starter-test test + + + com.baomidou + mybatis-plus-boot-starter + 3.5.3 + diff --git a/src/main/java/xyz/playedu/api/config/MybatisPlusConfig.java b/src/main/java/xyz/playedu/api/config/MybatisPlusConfig.java new file mode 100644 index 0000000..e4dfa89 --- /dev/null +++ b/src/main/java/xyz/playedu/api/config/MybatisPlusConfig.java @@ -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; + } + +} diff --git a/src/main/java/xyz/playedu/api/controller/admin/AdminUserController.java b/src/main/java/xyz/playedu/api/controller/admin/AdminUserController.java new file mode 100644 index 0000000..df0255f --- /dev/null +++ b/src/main/java/xyz/playedu/api/controller/admin/AdminUserController.java @@ -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 List(@RequestParam("page") Integer page, @RequestParam("size") Integer size) { + PageResult result = adminUserService.paginate(page, size, null); + return result; + } + +} diff --git a/src/main/java/xyz/playedu/api/domain/AdminUser.java b/src/main/java/xyz/playedu/api/domain/AdminUser.java new file mode 100644 index 0000000..5a6f77d --- /dev/null +++ b/src/main/java/xyz/playedu/api/domain/AdminUser.java @@ -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(); + } +} \ No newline at end of file diff --git a/src/main/java/xyz/playedu/api/mapper/AdminUserMapper.java b/src/main/java/xyz/playedu/api/mapper/AdminUserMapper.java new file mode 100644 index 0000000..1bb6ac2 --- /dev/null +++ b/src/main/java/xyz/playedu/api/mapper/AdminUserMapper.java @@ -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 { + +} + + + + diff --git a/src/main/java/xyz/playedu/api/service/AdminUserService.java b/src/main/java/xyz/playedu/api/service/AdminUserService.java new file mode 100644 index 0000000..004d1b5 --- /dev/null +++ b/src/main/java/xyz/playedu/api/service/AdminUserService.java @@ -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 { + +} diff --git a/src/main/java/xyz/playedu/api/service/impl/AdminUserServiceImpl.java b/src/main/java/xyz/playedu/api/service/impl/AdminUserServiceImpl.java new file mode 100644 index 0000000..ec69fc7 --- /dev/null +++ b/src/main/java/xyz/playedu/api/service/impl/AdminUserServiceImpl.java @@ -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 implements AdminUserService { + + public PageResult paginate(int page, int size, Wrapper queryWrapper) { + IPage userPage = new Page<>(page, size); + userPage = this.getBaseMapper().selectPage(userPage, queryWrapper); + + PageResult pageResult = new PageResult<>(); + pageResult.setData(userPage.getRecords()); + pageResult.setTotal(userPage.getTotal()); + + return pageResult; + } + +} + + + + diff --git a/src/main/java/xyz/playedu/api/types/PageResult.java b/src/main/java/xyz/playedu/api/types/PageResult.java new file mode 100644 index 0000000..40b95ff --- /dev/null +++ b/src/main/java/xyz/playedu/api/types/PageResult.java @@ -0,0 +1,26 @@ +package xyz.playedu.api.types; + +import java.util.List; + +public class PageResult { + + private List data; + + private Long total; + + public List getData() { + return data; + } + + public void setData(List data) { + this.data = data; + } + + public Long getTotal() { + return total; + } + + public void setTotal(Long total) { + this.total = total; + } +} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 61d8695..ef4533a 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,4 +1,7 @@ spring.profiles.active=dev #mybatis -mybatis.mapper-locations=classpath:mapper/*.xml \ No newline at end of file +mybatis.mapper-locations=classpath:mapper/*.xml + +#mybatis-plus +mybatis-plus.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl \ No newline at end of file diff --git a/src/main/resources/mapper/AdminUserMapper.xml b/src/main/resources/mapper/AdminUserMapper.xml new file mode 100644 index 0000000..9fd2235 --- /dev/null +++ b/src/main/resources/mapper/AdminUserMapper.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + id,name,email, + password,login_ip,login_at, + is_ban_login,login_times,created_at, + updated_at + +