空
package com.company.springbootmybatisplus.dao;
import com.company.springbootmybatisplus.po.UserPO;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Repository;
/**
* @author xindaqi
* @since 2020-08-15
*/
@Mapper
public interface UserDAO extends BaseMapper<UserPO>{
}
package com.company.springbootmybatisplus.service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.company.springbootmybatisplus.dto.UserQueryInputDTO;
import com.company.springbootmybatisplus.po.UserPO;
import com.baomidou.mybatisplus.extension.service.IService;
import com.company.springbootmybatisplus.vo.UserDetailsVO;
import java.util.List;
/**
* @author xindaqi
* @since 2020-08-15
*/
public interface UserService extends IService<UserPO> {
IPage<UserPO> pageQuery(UserQueryInputDTO params);
}
package com.company.springbootmybatisplus.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.company.springbootmybatisplus.dto.UserQueryInputDTO;
import com.company.springbootmybatisplus.vo.UserDetailsVO;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.company.springbootmybatisplus.service.UserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.company.springbootmybatisplus.dao.UserDAO;
import com.company.springbootmybatisplus.po.UserPO;
import java.util.List;
import org.springframework.util.StringUtils;
/**
* @author xindaqi
* @since 2020-08-15
*/
@Service
@Transactional
public class UserServiceImpl extends ServiceImpl<UserDAO, UserPO> implements UserService{
@Override
public IPage<UserPO> pageQuery(UserQueryInputDTO params){
IPage<UserPO> page = new Page<>(params.getPageStart(), params.getPageSize());
QueryWrapper<UserPO> wrapper = new QueryWrapper<>();
wrapper.select("id", "name", "sex", "uid")
.lambda()
.eq(UserPO::getIsDelete, 0)
.like(!StringUtils.isEmpty(params.getUserName()), UserPO::getName, params.getUserName());
this.baseMapper.selectPage(page, wrapper);
return page;
}
}
package com.company.springbootmybatisplus.controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.company.springbootmybatisplus.vo.UserDetailsVO;
import org.springframework.web.bind.annotation.*;
import org.springframework.util.StringUtils;
import com.company.springbootmybatisplus.dto.*;
import com.company.springbootmybatisplus.po.UserPO;
import com.company.springbootmybatisplus.utils.ResultJson;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import com.company.springbootmybatisplus.service.UserService;
import org.springframework.beans.BeanUtils;
import com.company.springbootmybatisplus.enums.CodeEnum;
import org.springframework.beans.factory.annotation.Value;
import java.time.LocalDateTime;
import java.util.List;
import java.util.ArrayList;
import java.util.stream.Collectors;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import com.company.springbootmybatisplus.vo.UserDetailsVO;
/**
* @author xindaqi
* @since 2020-08-15
*/
@CrossOrigin(origins = "*", maxAge = 3600)
@RestController
@RequestMapping("/api/v1")
@Api(tags = "人员配置")
public class UserInfosController{
static Logger logger = LoggerFactory.getLogger(UserInfosController.class);
@Autowired
private UserService userService;
@Value("${third.url}")
private String url;
@RequestMapping(value="/user/add", method=RequestMethod.POST)
@ApiImplicitParam(name = "userAddInputDTO", value = "用户信息", dataType = "UserAddInputDTO", paramType = "body")
@ApiOperation("新增人员")
public ResultJson addUser(@RequestBody UserAddInputDTO userAddInputDTO){
logger.info("Add user");
UserPO userPO = new UserPO();
BeanUtils.copyProperties(userAddInputDTO, userPO);
LocalDateTime ldt = LocalDateTime.now();
userPO.setCreateAt(ldt);
userService.save(userPO);
return new ResultJson(true, CodeEnum.SUCCESS.getCode());
}
}
package com.company.springbootmybatisplus.controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.company.springbootmybatisplus.vo.UserDetailsVO;
import org.springframework.web.bind.annotation.*;
import org.springframework.util.StringUtils;
import com.company.springbootmybatisplus.dto.*;
import com.company.springbootmybatisplus.po.UserPO;
import com.company.springbootmybatisplus.utils.ResultJson;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import com.company.springbootmybatisplus.service.UserService;
import org.springframework.beans.BeanUtils;
import com.company.springbootmybatisplus.enums.CodeEnum;
import org.springframework.beans.factory.annotation.Value;
import java.time.LocalDateTime;
import java.util.List;
import java.util.ArrayList;
import java.util.stream.Collectors;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import com.company.springbootmybatisplus.vo.UserDetailsVO;
/**
* @author xindaqi
* @since 2020-08-15
*/
@CrossOrigin(origins = "*", maxAge = 3600)
@RestController
@RequestMapping("/api/v1")
@Api(tags = "人员配置")
public class UserInfosController{
static Logger logger = LoggerFactory.getLogger(UserInfosController.class);
@Autowired
private UserService userService;
@Value("${third.url}")
private String url;
@RequestMapping(value="/user/delete", params={
"id"}, method=RequestMethod.DELETE)
@ApiImplicitParam(name = "id", value = "用户ID", dataType = "Integer", paramType = "query")
@ApiOperation("删除人员")
public ResultJson deleteUser(@RequestParam("id") Integer id){
userService.removeById(id);
return new ResultJson(true, CodeEnum.SUCCESS.getCode());
}
}
package com.company.springbootmybatisplus.controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.company.springbootmybatisplus.vo.UserDetailsVO;
import org.springframework.web.bind.annotation.*;
import org.springframework.util.StringUtils;
import com.company.springbootmybatisplus.dto.*;
import com.company.springbootmybatisplus.po.UserPO;
import com.company.springbootmybatisplus.utils.ResultJson;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import com.company.springbootmybatisplus.service.UserService;
import org.springframework.beans.BeanUtils;
import com.company.springbootmybatisplus.enums.CodeEnum;
import org.springframework.beans.factory.annotation.Value;
import java.time.LocalDateTime;
import java.util.List;
import java.util.ArrayList;
import java.util.stream.Collectors;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import com.company.springbootmybatisplus.vo.UserDetailsVO;
/**
* @author xindaqi
* @since 2020-08-15
*/
@CrossOrigin(origins = "*", maxAge = 3600)
@RestController
@RequestMapping("/api/v1")
@Api(tags = "人员配置")
public class UserInfosController{
static Logger logger = LoggerFactory.getLogger(UserInfosController.class);
@Autowired
private UserService userService;
@Value("${third.url}")
private String url;
@RequestMapping(value="/user/update", method=RequestMethod.POST)
@ApiImplicitParam(name = "userUpdateInputDTO", value = "更新人员信息", dataType = "UserUpdateInputDTO", paramType = "body")
@ApiOperation("修改人员信息")
public ResultJson updateUser(@RequestBody UserUpdateInputDTO userUpdateInputDTO){
UserPO userPO = new UserPO();
BeanUtils.copyProperties(userUpdateInputDTO, userPO);
userService.updateById(userPO);
return new ResultJson(true, CodeEnum.SUCCESS.getCode());
}
}
package com.company.springbootmybatisplus.controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.company.springbootmybatisplus.vo.UserDetailsVO;
import org.springframework.web.bind.annotation.*;
import org.springframework.util.StringUtils;
import com.company.springbootmybatisplus.dto.*;
import com.company.springbootmybatisplus.po.UserPO;
import com.company.springbootmybatisplus.utils.ResultJson;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import com.company.springbootmybatisplus.service.UserService;
import org.springframework.beans.BeanUtils;
import com.company.springbootmybatisplus.enums.CodeEnum;
import org.springframework.beans.factory.annotation.Value;
import java.time.LocalDateTime;
import java.util.List;
import java.util.ArrayList;
import java.util.stream.Collectors;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import com.company.springbootmybatisplus.vo.UserDetailsVO;
/**
* @author xindaqi
* @since 2020-08-15
*/
@CrossOrigin(origins = "*", maxAge = 3600)
@RestController
@RequestMapping("/api/v1")
@Api(tags = "人员配置")
public class UserInfosController{
static Logger logger = LoggerFactory.getLogger(UserInfosController.class);
@Autowired
private UserService userService;
@Value("${third.url}")
private String url;
@RequestMapping(value = "/user/details", method=RequestMethod.GET)
@ApiOperation("查询人员详情")
@ApiImplicitParam(name = "id", value = "用户id", dataType = "Integer", paramType = "query")
public ResultJson<UserDetailsVO> detailsUser(@RequestParam("id") Integer id){
UserPO userPO = userService.getById(id);
if(null == userPO){
return new ResultJson(true, CodeEnum.NOT_FOUND.code, CodeEnum.NOT_FOUND.description);
}
UserDetailsVO userDetailsVO = new UserDetailsVO();
BeanUtils.copyProperties(userPO, userDetailsVO);
return new ResultJson(true, CodeEnum.SUCCESS.getCode(), userDetailsVO);
}
}
package com.company.springbootmybatisplus.controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.company.springbootmybatisplus.vo.UserDetailsVO;
import org.springframework.web.bind.annotation.*;
import org.springframework.util.StringUtils;
import com.company.springbootmybatisplus.dto.*;
import com.company.springbootmybatisplus.po.UserPO;
import com.company.springbootmybatisplus.utils.ResultJson;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import com.company.springbootmybatisplus.service.UserService;
import org.springframework.beans.BeanUtils;
import com.company.springbootmybatisplus.enums.CodeEnum;
import org.springframework.beans.factory.annotation.Value;
import java.time.LocalDateTime;
import java.util.List;
import java.util.ArrayList;
import java.util.stream.Collectors;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import com.company.springbootmybatisplus.vo.UserDetailsVO;
/**
* @author xindaqi
* @since 2020-08-15
*/
@CrossOrigin(origins = "*", maxAge = 3600)
@RestController
@RequestMapping("/api/v1")
@Api(tags = "人员配置")
public class UserInfosController{
static Logger logger = LoggerFactory.getLogger(UserInfosController.class);
@Autowired
private UserService userService;
@Value("${third.url}")
private String url;
@RequestMapping(value="/user/query/page", method=RequestMethod.POST)
@ApiImplicitParam(name = "userQueryInputDTO", value = "分页查询人员信息", dataType = "UserQueryInputDTO", paramType = "body")
@ApiOperation("分页查询人员信息")
public ResultJson queryUserInPage(@RequestBody UserQueryInputDTO userQueryInputDTO){
IPage<UserPO> page = new Page<UserPO>(userQueryInputDTO.getPageStart(), userQueryInputDTO.getPageSize());
QueryWrapper<UserPO> wrapper = new QueryWrapper<>();
if(!StringUtils.isEmpty(userQueryInputDTO.getUserName())){
wrapper.like("name", userQueryInputDTO.getUserName());
}
IPage<UserPO> usersPage = userService.page(page, wrapper);
List<UserPO> userInfos = usersPage.getRecords();
long total = usersPage.getTotal();
return ResultJson.success(total, userInfos);
}
}
package com.company.springbootmybatisplus.controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.company.springbootmybatisplus.vo.UserDetailsVO;
import org.springframework.web.bind.annotation.*;
import org.springframework.util.StringUtils;
import com.company.springbootmybatisplus.dto.*;
import com.company.springbootmybatisplus.po.UserPO;
import com.company.springbootmybatisplus.utils.ResultJson;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import com.company.springbootmybatisplus.service.UserService;
import org.springframework.beans.BeanUtils;
import com.company.springbootmybatisplus.enums.CodeEnum;
import org.springframework.beans.factory.annotation.Value;
import java.time.LocalDateTime;
import java.util.List;
import java.util.ArrayList;
import java.util.stream.Collectors;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import com.company.springbootmybatisplus.vo.UserDetailsVO;
/**
* @author xindaqi
* @since 2020-08-15
*/
@CrossOrigin(origins = "*", maxAge = 3600)
@RestController
@RequestMapping("/api/v1")
@Api(tags = "人员配置")
public class UserInfosController{
static Logger logger = LoggerFactory.getLogger(UserInfosController.class);
@Autowired
private UserService userService;
@Value("${third.url}")
private String url;
@RequestMapping(value="/user/query/pageli", method=RequestMethod.POST)
public ResultJson queryUserInPageLi(@RequestBody UserQueryInputDTO params){
IPage<UserPO> usersPage = userService.pageQuery(params);
List<UserPO> userLi = usersPage.getRecords();
long total = usersPage.getTotal();
return ResultJson.success(total, userLi);
}
}
【参考文献】
[1]https://www.cnblogs.com/yizhixiang/p/13657830.html
[2]https://blog.csdn.net/womenyiqilalala/article/details/95073892
[3]https://www.jianshu.com/p/07be9ccb3306
[4]https://www.cnblogs.com/2393920029-qq/p/13496810.html