🎉 init基本用户信息查询
This commit is contained in:
parent
5f2e3289d4
commit
219412c68c
|
@ -0,0 +1,69 @@
|
||||||
|
package com.spring.step2.controller;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.spring.step2.domain.dto.UserDto;
|
||||||
|
import com.spring.step2.domain.entity.UserEntity;
|
||||||
|
import com.spring.step2.domain.vo.UserVo;
|
||||||
|
import com.spring.step2.domain.vo.result.PageResult;
|
||||||
|
import com.spring.step2.domain.vo.result.Result;
|
||||||
|
import com.spring.step2.domain.vo.result.ResultCodeEnum;
|
||||||
|
import com.spring.step2.service.UserService;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import jakarta.validation.Valid;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 用户 前端控制器
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author Bunny
|
||||||
|
* @since 2025-07-11 14:49:46
|
||||||
|
*/
|
||||||
|
@Tag(name = "用户", description = "用户相关接口")
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/user/user")
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class UserController {
|
||||||
|
|
||||||
|
private final UserService userService;
|
||||||
|
|
||||||
|
@Operation(summary = "分页查询用户", description = "分页用户")
|
||||||
|
@GetMapping("{page}/{limit}")
|
||||||
|
public Result<PageResult<UserVo>> getUserPage(
|
||||||
|
@Parameter(name = "page", description = "当前页", required = true)
|
||||||
|
@PathVariable("page") Integer page,
|
||||||
|
@Parameter(name = "limit", description = "每页记录数", required = true)
|
||||||
|
@PathVariable("limit") Integer limit,
|
||||||
|
UserDto dto) {
|
||||||
|
Page<UserEntity> pageParams = new Page<>(page, limit);
|
||||||
|
PageResult<UserVo> pageResult = userService.getUserPage(pageParams, dto);
|
||||||
|
return Result.success(pageResult);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "添加用户", description = "添加用户")
|
||||||
|
@PostMapping()
|
||||||
|
public Result<String> addUser(@Valid @RequestBody UserDto dto) {
|
||||||
|
userService.addUser(dto);
|
||||||
|
return Result.success(ResultCodeEnum.ADD_SUCCESS);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "更新用户", description = "更新用户")
|
||||||
|
@PutMapping()
|
||||||
|
public Result<String> updateUser(@Valid @RequestBody UserDto dto) {
|
||||||
|
userService.updateUser(dto);
|
||||||
|
return Result.success(ResultCodeEnum.UPDATE_SUCCESS);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "删除用户", description = "删除用户")
|
||||||
|
@DeleteMapping()
|
||||||
|
public Result<String> deleteUser(@RequestBody List<Long> ids) {
|
||||||
|
userService.deleteUser(ids);
|
||||||
|
return Result.success(ResultCodeEnum.DELETE_SUCCESS);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,69 @@
|
||||||
|
package com.spring.step2.controller;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.spring.step2.domain.dto.UsersDto;
|
||||||
|
import com.spring.step2.domain.entity.UsersEntity;
|
||||||
|
import com.spring.step2.domain.vo.UsersVo;
|
||||||
|
import com.spring.step2.domain.vo.result.PageResult;
|
||||||
|
import com.spring.step2.domain.vo.result.Result;
|
||||||
|
import com.spring.step2.domain.vo.result.ResultCodeEnum;
|
||||||
|
import com.spring.step2.service.UsersService;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import jakarta.validation.Valid;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 前端控制器
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author Bunny
|
||||||
|
* @since 2025-07-11 14:49:46
|
||||||
|
*/
|
||||||
|
@Tag(name = "Csharp用户接口查询", description = "用户接口查询相关接口")
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/user/users")
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class UsersController {
|
||||||
|
|
||||||
|
private final UsersService usersService;
|
||||||
|
|
||||||
|
@Operation(summary = "分页查询", description = "分页")
|
||||||
|
@GetMapping("{page}/{limit}")
|
||||||
|
public Result<PageResult<UsersVo>> getUsersPage(
|
||||||
|
@Parameter(name = "page", description = "当前页", required = true)
|
||||||
|
@PathVariable("page") Integer page,
|
||||||
|
@Parameter(name = "limit", description = "每页记录数", required = true)
|
||||||
|
@PathVariable("limit") Integer limit,
|
||||||
|
UsersDto dto) {
|
||||||
|
Page<UsersEntity> pageParams = new Page<>(page, limit);
|
||||||
|
PageResult<UsersVo> pageResult = usersService.getUsersPage(pageParams, dto);
|
||||||
|
return Result.success(pageResult);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "添加", description = "添加")
|
||||||
|
@PostMapping()
|
||||||
|
public Result<String> addUsers(@Valid @RequestBody UsersDto dto) {
|
||||||
|
usersService.addUsers(dto);
|
||||||
|
return Result.success(ResultCodeEnum.ADD_SUCCESS);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "更新", description = "更新")
|
||||||
|
@PutMapping()
|
||||||
|
public Result<String> updateUsers(@Valid @RequestBody UsersDto dto) {
|
||||||
|
usersService.updateUsers(dto);
|
||||||
|
return Result.success(ResultCodeEnum.UPDATE_SUCCESS);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "删除", description = "删除")
|
||||||
|
@DeleteMapping()
|
||||||
|
public Result<String> deleteUsers(@RequestBody List<Long> ids) {
|
||||||
|
usersService.deleteUsers(ids);
|
||||||
|
return Result.success(ResultCodeEnum.DELETE_SUCCESS);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,45 @@
|
||||||
|
package com.spring.step2.domain.dto;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Builder
|
||||||
|
@Schema(name = "UserDTO对象", title = "用户", description = "用户的DTO对象")
|
||||||
|
public class UserDto {
|
||||||
|
|
||||||
|
@Schema(name = "id", title = "主键")
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
@Schema(name = "username", title = "用户名")
|
||||||
|
private String username;
|
||||||
|
|
||||||
|
@Schema(name = "password", title = "密码")
|
||||||
|
private String password;
|
||||||
|
|
||||||
|
@Schema(name = "email", title = "邮箱")
|
||||||
|
private String email;
|
||||||
|
|
||||||
|
@Schema(name = "createTime", title = "创建时间")
|
||||||
|
private LocalDateTime createTime;
|
||||||
|
|
||||||
|
@Schema(name = "updateTime", title = "更新时间")
|
||||||
|
private LocalDateTime updateTime;
|
||||||
|
|
||||||
|
@Schema(name = "createUser", title = "创建用户")
|
||||||
|
private Long createUser;
|
||||||
|
|
||||||
|
@Schema(name = "updateUser", title = "更新用户")
|
||||||
|
private Long updateUser;
|
||||||
|
|
||||||
|
@Schema(name = "isDeleted", title = "是否被删除")
|
||||||
|
private Boolean isDeleted;
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,30 @@
|
||||||
|
package com.spring.step2.domain.entity;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableLogic;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@Accessors(chain = true)
|
||||||
|
@TableName("t_user")
|
||||||
|
@Schema(name = "User对象", title = "用户", description = "用户的实体类对象")
|
||||||
|
public class UserEntity extends BaseEntity {
|
||||||
|
|
||||||
|
@Schema(name = "username", title = "用户名")
|
||||||
|
private String username;
|
||||||
|
|
||||||
|
@Schema(name = "password", title = "密码")
|
||||||
|
private String password;
|
||||||
|
|
||||||
|
@Schema(name = "email", title = "邮箱")
|
||||||
|
private String email;
|
||||||
|
|
||||||
|
@Schema(name = "isDeleted", title = "是否被删除")
|
||||||
|
@TableLogic
|
||||||
|
private Boolean isDeleted;
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,44 @@
|
||||||
|
package com.spring.step2.domain.vo;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Schema(name = "UserVO对象", title = "用户", description = "用户的VO对象")
|
||||||
|
public class UserVo {
|
||||||
|
|
||||||
|
@Schema(name = "id", title = "主键")
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
@Schema(name = "username", title = "用户名")
|
||||||
|
private String username;
|
||||||
|
|
||||||
|
@Schema(name = "password", title = "密码")
|
||||||
|
private String password;
|
||||||
|
|
||||||
|
@Schema(name = "email", title = "邮箱")
|
||||||
|
private String email;
|
||||||
|
|
||||||
|
@Schema(name = "createTime", title = "创建时间")
|
||||||
|
private LocalDateTime createTime;
|
||||||
|
|
||||||
|
@Schema(name = "updateTime", title = "更新时间")
|
||||||
|
private LocalDateTime updateTime;
|
||||||
|
|
||||||
|
@Schema(name = "createUser", title = "创建用户")
|
||||||
|
private Long createUser;
|
||||||
|
|
||||||
|
@Schema(name = "updateUser", title = "更新用户")
|
||||||
|
private Long updateUser;
|
||||||
|
|
||||||
|
@Schema(name = "isDeleted", title = "是否被删除")
|
||||||
|
private Boolean isDeleted;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
package com.spring.step2.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.dynamic.datasource.annotation.DS;
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.spring.step2.domain.dto.UserDto;
|
||||||
|
import com.spring.step2.domain.entity.UserEntity;
|
||||||
|
import com.spring.step2.domain.vo.UserVo;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 用户 Mapper 接口
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author Bunny
|
||||||
|
* @since 2025-07-11 14:49:46
|
||||||
|
*/
|
||||||
|
@DS("testJwt")
|
||||||
|
@Mapper
|
||||||
|
public interface UserMapper extends BaseMapper<UserEntity> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* * 分页查询用户内容
|
||||||
|
*
|
||||||
|
* @param pageParams 用户分页参数
|
||||||
|
* @param dto 用户查询表单
|
||||||
|
* @return 用户分页结果
|
||||||
|
*/
|
||||||
|
IPage<UserVo> selectListByPage(@Param("page") Page<UserEntity> pageParams, @Param("dto") UserDto dto);
|
||||||
|
|
||||||
|
}
|
|
@ -10,7 +10,7 @@ import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class CustomUserDetailsService implements UserDetailsService {
|
public class InMemoryUserDetailsService implements UserDetailsService {
|
||||||
|
|
||||||
private final PasswordEncoder passwordEncoder;
|
private final PasswordEncoder passwordEncoder;
|
||||||
|
|
|
@ -0,0 +1,49 @@
|
||||||
|
package com.spring.step2.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.spring.step2.domain.dto.UserDto;
|
||||||
|
import com.spring.step2.domain.entity.UserEntity;
|
||||||
|
import com.spring.step2.domain.vo.UserVo;
|
||||||
|
import com.spring.step2.domain.vo.result.PageResult;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 用户 服务类
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author Bunny
|
||||||
|
* @since 2025-07-11 14:49:46
|
||||||
|
*/
|
||||||
|
public interface UserService extends IService<UserEntity> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页查询用户
|
||||||
|
*
|
||||||
|
* @return {@link UserVo}
|
||||||
|
*/
|
||||||
|
PageResult<UserVo> getUserPage(Page<UserEntity> pageParams, UserDto dto);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加用户
|
||||||
|
*
|
||||||
|
* @param dto {@link UserDto} 添加表单
|
||||||
|
*/
|
||||||
|
void addUser(UserDto dto);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新用户
|
||||||
|
*
|
||||||
|
* @param dto {@link UserDto} 更新表单
|
||||||
|
*/
|
||||||
|
void updateUser(UserDto dto);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除|批量删除用户类型
|
||||||
|
*
|
||||||
|
* @param ids 删除id列表
|
||||||
|
*/
|
||||||
|
void deleteUser(List<Long> ids);
|
||||||
|
}
|
|
@ -0,0 +1,49 @@
|
||||||
|
package com.spring.step2.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.spring.step2.domain.dto.UsersDto;
|
||||||
|
import com.spring.step2.domain.entity.UsersEntity;
|
||||||
|
import com.spring.step2.domain.vo.UsersVo;
|
||||||
|
import com.spring.step2.domain.vo.result.PageResult;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 服务类
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author Bunny
|
||||||
|
* @since 2025-07-11 14:49:46
|
||||||
|
*/
|
||||||
|
public interface UsersService extends IService<UsersEntity> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页查询
|
||||||
|
*
|
||||||
|
* @return {@link UsersVo}
|
||||||
|
*/
|
||||||
|
PageResult<UsersVo> getUsersPage(Page<UsersEntity> pageParams, UsersDto dto);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加
|
||||||
|
*
|
||||||
|
* @param dto {@link UsersDto} 添加表单
|
||||||
|
*/
|
||||||
|
void addUsers(UsersDto dto);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新
|
||||||
|
*
|
||||||
|
* @param dto {@link UsersDto} 更新表单
|
||||||
|
*/
|
||||||
|
void updateUsers(UsersDto dto);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除|批量删除类型
|
||||||
|
*
|
||||||
|
* @param ids 删除id列表
|
||||||
|
*/
|
||||||
|
void deleteUsers(List<Long> ids);
|
||||||
|
}
|
|
@ -0,0 +1,86 @@
|
||||||
|
package com.spring.step2.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.dynamic.datasource.annotation.DS;
|
||||||
|
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.spring.step2.domain.dto.UserDto;
|
||||||
|
import com.spring.step2.domain.entity.UserEntity;
|
||||||
|
import com.spring.step2.domain.vo.UserVo;
|
||||||
|
import com.spring.step2.domain.vo.result.PageResult;
|
||||||
|
import com.spring.step2.mapper.UserMapper;
|
||||||
|
import com.spring.step2.service.UserService;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.beans.BeanUtils;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 用户 服务实现类
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author Bunny
|
||||||
|
* @since 2025-07-11 14:49:46
|
||||||
|
*/
|
||||||
|
@DS("testJwt")
|
||||||
|
@Service
|
||||||
|
@Transactional
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class UserServiceImpl extends ServiceImpl<UserMapper, UserEntity> implements UserService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* * 用户 服务实现类
|
||||||
|
*
|
||||||
|
* @param pageParams 用户分页查询page对象
|
||||||
|
* @param dto 用户分页查询对象
|
||||||
|
* @return 查询分页用户返回对象
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public PageResult<UserVo> getUserPage(Page<UserEntity> pageParams, UserDto dto) {
|
||||||
|
IPage<UserVo> page = baseMapper.selectListByPage(pageParams, dto);
|
||||||
|
|
||||||
|
return PageResult.<UserVo>builder()
|
||||||
|
.list(page.getRecords())
|
||||||
|
.pageNo(page.getCurrent())
|
||||||
|
.pageSize(page.getSize())
|
||||||
|
.total(page.getTotal())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加用户
|
||||||
|
*
|
||||||
|
* @param dto 用户添加
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void addUser(UserDto dto) {
|
||||||
|
UserEntity user = new UserEntity();
|
||||||
|
BeanUtils.copyProperties(dto, user);
|
||||||
|
save(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新用户
|
||||||
|
*
|
||||||
|
* @param dto 用户更新
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void updateUser(UserDto dto) {
|
||||||
|
UserEntity user = new UserEntity();
|
||||||
|
BeanUtils.copyProperties(dto, user);
|
||||||
|
updateById(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除|批量删除用户
|
||||||
|
*
|
||||||
|
* @param ids 删除id列表
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void deleteUser(List<Long> ids) {
|
||||||
|
removeByIds(ids);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,86 @@
|
||||||
|
package com.spring.step2.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.dynamic.datasource.annotation.DS;
|
||||||
|
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.spring.step2.domain.dto.UsersDto;
|
||||||
|
import com.spring.step2.domain.entity.UsersEntity;
|
||||||
|
import com.spring.step2.domain.vo.UsersVo;
|
||||||
|
import com.spring.step2.domain.vo.result.PageResult;
|
||||||
|
import com.spring.step2.mapper.UsersMapper;
|
||||||
|
import com.spring.step2.service.UsersService;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.beans.BeanUtils;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 服务实现类
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author Bunny
|
||||||
|
* @since 2025-07-11 14:49:46
|
||||||
|
*/
|
||||||
|
@DS("testJwt")
|
||||||
|
@Service
|
||||||
|
@Transactional
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class UsersServiceImpl extends ServiceImpl<UsersMapper, UsersEntity> implements UsersService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* * 服务实现类
|
||||||
|
*
|
||||||
|
* @param pageParams 分页查询page对象
|
||||||
|
* @param dto 分页查询对象
|
||||||
|
* @return 查询分页返回对象
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public PageResult<UsersVo> getUsersPage(Page<UsersEntity> pageParams, UsersDto dto) {
|
||||||
|
IPage<UsersVo> page = baseMapper.selectListByPage(pageParams, dto);
|
||||||
|
|
||||||
|
return PageResult.<UsersVo>builder()
|
||||||
|
.list(page.getRecords())
|
||||||
|
.pageNo(page.getCurrent())
|
||||||
|
.pageSize(page.getSize())
|
||||||
|
.total(page.getTotal())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加
|
||||||
|
*
|
||||||
|
* @param dto 添加
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void addUsers(UsersDto dto) {
|
||||||
|
UsersEntity users = new UsersEntity();
|
||||||
|
BeanUtils.copyProperties(dto, users);
|
||||||
|
save(users);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新
|
||||||
|
*
|
||||||
|
* @param dto 更新
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void updateUsers(UsersDto dto) {
|
||||||
|
UsersEntity users = new UsersEntity();
|
||||||
|
BeanUtils.copyProperties(dto, users);
|
||||||
|
updateById(users);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除|批量删除
|
||||||
|
*
|
||||||
|
* @param ids 删除id列表
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void deleteUsers(List<Long> ids) {
|
||||||
|
removeByIds(ids);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,42 @@
|
||||||
|
<?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="com.spring.step2.mapper.UserMapper">
|
||||||
|
|
||||||
|
<!-- 通用查询映射结果 -->
|
||||||
|
<resultMap id="BaseResultMap" type="com.spring.step2.domain.entity.UserEntity">
|
||||||
|
<id column="id" property="id"/>
|
||||||
|
<id column="username" property="username"/>
|
||||||
|
<id column="password" property="password"/>
|
||||||
|
<id column="email" property="email"/>
|
||||||
|
<id column="create_time" property="createTime"/>
|
||||||
|
<id column="update_time" property="updateTime"/>
|
||||||
|
<id column="create_user" property="createUser"/>
|
||||||
|
<id column="update_user" property="updateUser"/>
|
||||||
|
<id column="is_deleted" property="isDeleted"/>
|
||||||
|
</resultMap>
|
||||||
|
|
||||||
|
<!-- 通用查询结果列 -->
|
||||||
|
<sql id="Base_Column_List">
|
||||||
|
id,username,password,email,create_time,update_time,create_user,update_user,is_deleted
|
||||||
|
</sql>
|
||||||
|
|
||||||
|
<!-- 分页查询用户内容 -->
|
||||||
|
<select id="selectListByPage" resultType="com.spring.step2.domain.vo.UserVo">
|
||||||
|
select
|
||||||
|
<include refid="Base_Column_List"/>
|
||||||
|
from t_user
|
||||||
|
<where>
|
||||||
|
is_deleted = 0
|
||||||
|
<if test="dto.id != null and dto.id != ''">
|
||||||
|
and id like CONCAT('%',#{dto.id},'%')
|
||||||
|
</if>
|
||||||
|
<if test="dto.username != null and dto.username != ''">
|
||||||
|
and username like CONCAT('%',#{dto.username},'%')
|
||||||
|
</if>
|
||||||
|
<if test="dto.email != null and dto.email != ''">
|
||||||
|
and email like CONCAT('%',#{dto.email},'%')
|
||||||
|
</if>
|
||||||
|
</where>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
</mapper>
|
Loading…
Reference in New Issue