Commit 667ba8be authored by duanledexianxianxian's avatar duanledexianxianxian 😁

init

parent 153cbf27
......@@ -84,3 +84,5 @@ buildNumber.properties
/.idea/.name
/.idea/vcs.xml
.idea
/demo-parent.iml
/demo/demo.iml
package com.duanledexianxianxian.demo.contoller;
import com.duanledexianxianxian.demo.domain.model.query.MenuForm;
import com.duanledexianxianxian.demo.service.IMenuService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
/**
* 菜单接口
*
* @author duanledexianxianxian
* @since 2020 -03-19
*/
@RestController
@RequestMapping("/api/v1/menus")
@Slf4j
public class MenuController {
/**
* The Menu service.
*/
@Autowired
private IMenuService menuService;
/**
* 添加菜单
*
* @param form 菜单表单
* @return the long
*/
@PostMapping
public Long addMenu(@RequestBody MenuForm form) {
return menuService.addMenu(form);
}
/**
* 编辑菜单
*
* @param form 菜单表单
* @return the long
*/
@PutMapping
public Boolean editMenu(@RequestBody MenuForm form) {
return menuService.editMenu(form);
}
/**
* 编辑菜单
*
* @param menuId 菜单编码
* @return the long
*/
@DeleteMapping("/{menuId}")
public Boolean deleteMenu(@PathVariable("menuId") Long menuId) {
return menuService.deleteMenu(menuId);
}
}
package com.duanledexianxianxian.demo.contoller;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.duanledexianxianxian.demo.common.util.BeanUtils;
import com.duanledexianxianxian.demo.domain.dto.UserDTO;
import com.duanledexianxianxian.demo.domain.model.query.MenuForm;
import com.duanledexianxianxian.demo.domain.model.query.UserForm;
import com.duanledexianxianxian.demo.domain.model.query.UserQuery;
import com.duanledexianxianxian.demo.domain.model.vo.MenuVO;
import com.duanledexianxianxian.demo.domain.model.vo.UserDetailVO;
import com.duanledexianxianxian.demo.domain.model.vo.UserVO;
import com.duanledexianxianxian.demo.service.IMenuService;
import com.duanledexianxianxian.demo.service.IUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;
import java.awt.*;
import java.util.List;
/**
* 用户接口
*
* @author duanledexianxianxian
* @since 2020 -03-19
*/
@RestController
@RequestMapping("/api/v1/users")
@Slf4j
public class UserController {
/**
* The Menu service.
*/
@Autowired
private IUserService userService;
/**
* 用户分页列表查询
*
* @param query the query
* @return the long
*/
@GetMapping
public IPage<UserVO> getUserListPage(UserQuery query) {
IPage page = userService.getUserListPage(query);
if (page != null && !CollectionUtils.isEmpty(page.getRecords())) {
page.setRecords(BeanUtils.copyList(page.getRecords(), UserVO.class));
}
return page;
}
/**
* 获取用户详情
*
* @param userId the user id
* @return the user menu list
*/
@GetMapping("/{userId}")
public UserDetailVO getUserMenuList(@PathVariable("userId")Long userId) {
UserDTO userDTO = userService.getUserDetail(userId);
return BeanUtils.copyObject(userDTO, UserDetailVO.class);
}
/**
* 添加用户
*
* @param form 用户表单
* @return the long
*/
@PostMapping
public Long addUser(@RequestBody UserForm form) {
return userService.addUser(form);
}
/**
* 编辑用户
*
* @param form 用户表单
* @return the long
*/
@PutMapping
public Boolean editUser(@RequestBody UserForm form) {
return userService.editUser(form);
}
/**
* 删除用户
*
* @param userId 用户编号
* @return the long
*/
@DeleteMapping("/{userId}")
public Boolean deleteUser(@PathVariable("userId") Long userId) {
return userService.deleteUser(userId);
}
}
package com.duanledexianxianxian.demo.dao;
import com.duanledexianxianxian.demo.domain.entity.Menu;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
/**
* <p>
* 菜单表 Mapper 接口
* </p>
*
* @author duanledexianxianxian
* @since 2020-03-19
*/
public interface MenuDao extends BaseMapper<Menu> {
}
package com.duanledexianxianxian.demo.dao;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.duanledexianxianxian.demo.domain.entity.User;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.duanledexianxianxian.demo.domain.model.query.UserQuery;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* <p>
* 用户表 Mapper 接口
* </p>
*
* @author duanledexianxianxian
* @since 2020 -03-19
*/
public interface UserDao extends BaseMapper<User> {
/**
* Gets list.
*
* @param page the page
* @param query the query
* @return the list
*/
List<User> getList(IPage<User> page, @Param("query") UserQuery query);
}
package com.duanledexianxianxian.demo.domain.entity;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import java.time.LocalDateTime;
import java.io.Serializable;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
/**
* <p>
* 菜单表
* </p>
*
* @author duanledexianxianxian
* @since 2020-03-19
*/
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("test_menu")
public class Menu implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 用户编号
*/
private Long userId;
/**
* 菜单编号
*/
@TableId
private Long menuId;
/**
* 菜单url
*/
private String menuUrl;
/**
* 菜单名称
*/
private String menuName;
/**
* 菜单编码
*/
private String menuCode;
/**
* 创建时间
*/
private LocalDateTime createTime;
}
package com.duanledexianxianxian.demo.domain.entity;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import java.time.LocalDate;
import java.io.Serializable;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
/**
* <p>
* 用户表
* </p>
*
* @author duanledexianxianxian
* @since 2020-03-19
*/
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("test_user")
public class User implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 用户编号
*/
@TableId
private Long userId;
/**
* 用户名称
*/
private String userName;
/**
* 用户昵称
*/
private String nickName;
/**
* 年龄
*/
private Integer age;
/**
* 生日
*/
private LocalDate birthday;
}
package com.duanledexianxianxian.demo.service;
import com.duanledexianxianxian.demo.domain.dto.MenuDTO;
import com.duanledexianxianxian.demo.domain.entity.Menu;
import com.baomidou.mybatisplus.extension.service.IService;
import com.duanledexianxianxian.demo.domain.model.query.MenuForm;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
/**
* <p>
* 菜单表 服务类
* </p>
*
* @author duanledexianxianxian
* @since 2020 -03-19
*/
public interface IMenuService extends IService<Menu> {
/**
* Add menu long.
*
* @param form the form
* @return the long
*/
Long addMenu(MenuForm form);
/**
* Edit menu boolean.
*
* @param form the form
* @return the boolean
*/
Boolean editMenu(MenuForm form);
/**
* Delete menu boolean.
*
* @param menuId the menu id
* @return the boolean
*/
Boolean deleteMenu(Long menuId);
/**
* Gets user menu list.
*
* @param userId the user id
* @return the user menu list
*/
List<MenuDTO> getUserMenuList(Long userId);
}
package com.duanledexianxianxian.demo.service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.duanledexianxianxian.demo.dao.UserDao;
import com.duanledexianxianxian.demo.domain.dto.MenuDTO;
import com.duanledexianxianxian.demo.domain.dto.UserDTO;
import com.duanledexianxianxian.demo.domain.entity.User;
import com.baomidou.mybatisplus.extension.service.IService;
import com.duanledexianxianxian.demo.domain.model.query.MenuForm;
import com.duanledexianxianxian.demo.domain.model.query.UserForm;
import com.duanledexianxianxian.demo.domain.model.query.UserQuery;
import java.util.List;
/**
* 用户接口
*
* @author duanledexianxianxian
* @since 2020 -03-19
*/
public interface IUserService extends IService<User> {
/**
* Add menu long.
*
* @param query the query
* @return the long
*/
IPage getUserListPage(UserQuery query);
/**
* Gets user menu list.
*
* @param userId the user id
* @return the user menu list
*/
UserDTO getUserDetail(Long userId);
/**
* Add menu long.
*
* @param form the form
* @return the long
*/
Long addUser(UserForm form);
/**
* Edit menu boolean.
*
* @param form the form
* @return the boolean
*/
Boolean editUser(UserForm form);
/**
* Delete menu boolean.
*
* @param userId the user id
* @return the boolean
*/
Boolean deleteUser(Long userId);
}
package com.duanledexianxianxian.demo.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
import com.duanledexianxianxian.demo.common.util.BeanUtils;
import com.duanledexianxianxian.demo.domain.dto.MenuDTO;
import com.duanledexianxianxian.demo.domain.entity.Menu;
import com.duanledexianxianxian.demo.dao.MenuDao;
import com.duanledexianxianxian.demo.domain.model.query.MenuForm;
import com.duanledexianxianxian.demo.service.IMenuService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
/**
* 菜单服务实现类
*
* @author duanledexianxianxian
* @since 2020 -03-19
*/
@Service
public class MenuServiceImpl extends ServiceImpl<MenuDao, Menu> implements IMenuService {
@Transactional(rollbackFor = Exception.class)
@Override
public Long addMenu(MenuForm form) {
// 做插入前检查
Menu menu = BeanUtils.copyObject(form, Menu.class);
this.baseMapper.insert(menu);
return menu.getMenuId();
}
@Transactional(rollbackFor = Exception.class)
@Override
public Boolean editMenu(MenuForm form) {
// 做编辑前检查
Menu menu = BeanUtils.copyObject(form, Menu.class);
int cnt = this.baseMapper.updateById(menu);
return SqlHelper.retBool(cnt);
}
@Transactional(rollbackFor = Exception.class)
@Override
public Boolean deleteMenu(Long menuId) {
// 做删除前检查
return SqlHelper.retBool(this.baseMapper.deleteById(menuId));
}
@Override
public List<MenuDTO> getUserMenuList(Long userId) {
return BeanUtils.copyList(this.baseMapper.selectList(new LambdaQueryWrapper<Menu>()
.eq(Menu::getUserId, userId)), MenuDTO.class);
}
}
package com.duanledexianxianxian.demo.service.impl;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
import com.duanledexianxianxian.demo.common.util.BeanUtils;
import com.duanledexianxianxian.demo.dao.MenuDao;
import com.duanledexianxianxian.demo.domain.dto.MenuDTO;
import com.duanledexianxianxian.demo.domain.dto.UserDTO;
import com.duanledexianxianxian.demo.domain.entity.Menu;
import com.duanledexianxianxian.demo.domain.entity.User;
import com.duanledexianxianxian.demo.dao.UserDao;
import com.duanledexianxianxian.demo.domain.model.query.UserForm;
import com.duanledexianxianxian.demo.domain.model.query.UserQuery;
import com.duanledexianxianxian.demo.service.IMenuService;
import com.duanledexianxianxian.demo.service.IUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.List;
/**
* 用户服务接口实现类
*
* @author duanledexianxianxian
* @since 2020 -03-19
*/
@Service
public class UserServiceImpl extends ServiceImpl<UserDao, User> implements IUserService {
@Autowired
IMenuService menuService;
@Override
public IPage getUserListPage(UserQuery query) {
IPage page = new Page(query.getPageNum(), query.getPageSize());
List<User> userList = this.baseMapper.getList(page, query);
page.setRecords(BeanUtils.copyList(userList, UserDTO.class));
return page;
}
@Override
public UserDTO getUserDetail(Long userId) {
User user = this.baseMapper.selectById(userId);
// 需要检查用户是否存在
UserDTO userDTO = BeanUtils.copyObject(user, UserDTO.class);
List<MenuDTO> menuDTOList = menuService.getUserMenuList(userId);
userDTO.setMenuList(menuDTOList);
return userDTO;
}
@Override
public Long addUser(UserForm form) {
// 做插入前检查
User user = BeanUtils.copyObject(form, User.class);
this.baseMapper.insert(user);
return user.getUserId();
}
@Override
public Boolean editUser(UserForm form) {
// 做编辑前检查
User user = BeanUtils.copyObject(form, User.class);
return SqlHelper.retBool(this.baseMapper.updateById(user));
}
@Override
public Boolean deleteUser(Long userId) {
// 做删除前检查
return SqlHelper.retBool(this.baseMapper.deleteById(userId));
}
}
<?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.duanledexianxianxian.demo.dao.MenuDao">
</mapper>
<?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.duanledexianxianxian.demo.dao.UserDao">
<!-- 通用查询映射结果 -->
<resultMap id="BaseResultMap" type="com.duanledexianxianxian.demo.domain.entity.User">
<id column="user_id" property="userId"/>
<result column="user_name" property="userName"/>
<result column="nick_name" property="nickName"/>
<result column="age" property="age"/>
<result column="birthday" property="birthday"/>
</resultMap>
<!-- 通用查询结果列 -->
<sql id="Base_Column_List">
user_id, user_name, nick_name, age, birthday
</sql>
<select id="getList" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from test_user
<where>
<if test="query.userName!=null and query.userName!=''">
and user_name like concat('%',#{query.userName})
</if>
<if test="query.nickName!=null and query.nickName!=''">
and nick_name like concat('%',#{query.nickName})
</if>
</where>
</select>
</mapper>
{
"info": {
"_postman_id": "3c980dec-3734-42c7-bfbb-f1fb6297506f",
"name": "Spingboot-demo",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item": [
{
"name": "用户-添加",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"name": "Content-Type",
"value": "application/json",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"birthday\": \"2020-05-20\",\n \"userName\": \"liubei\",\n \"nickName\": \"刘备\",\n \"age\": 50\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{url}}/users",
"host": [
"{{url}}"
],
"path": [
"users"
]
}
},
"response": []
},
{
"name": "用户-编辑",
"request": {
"method": "PUT",
"header": [
{
"key": "Content-Type",
"name": "Content-Type",
"value": "application/json",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{\n\t\"userId\":\"1240928784692322306\",\n \"birthday\": \"2020-05-20\",\n \"userName\": \"liubei\",\n \"nickName\": \"刘备\",\n \"age\": 60\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{url}}/users",
"host": [
"{{url}}"
],
"path": [
"users"
]
}
},
"response": []
},
{
"name": "用户-删除",
"request": {
"method": "DELETE",
"header": [],
"url": {
"raw": "{{url}}/users/:userId",
"host": [
"{{url}}"
],
"path": [
"users",
":userId"
],
"variable": [
{
"key": "userId",
"value": "1240928784692322306"
}
]
}
},
"response": []
},
{
"name": "用户-列表分页",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "{{url}}/users?pageNum=1&pageSize=10&userName&nickName",
"host": [
"{{url}}"
],
"path": [
"users"
],
"query": [
{
"key": "pageNum",
"value": "1"
},
{
"key": "pageSize",
"value": "10"
},
{
"key": "userName",
"value": null
},
{
"key": "nickName",
"value": null
}
]
}
},
"response": []
},
{
"name": "用户-用户详情",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "{{url}}/users/1?",
"host": [
"{{url}}"
],
"path": [
"users",
"1"
],
"query": [
{
"key": "pageNum",
"value": "1",
"disabled": true
},
{
"key": "pageSize",
"value": "10",
"disabled": true
},
{
"key": "userName",
"value": null,
"disabled": true
},
{
"key": "nickName",
"value": null,
"disabled": true
}
]
}
},
"response": []
},
{
"name": "菜单-添加",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"name": "Content-Type",
"value": "application/json",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{\n\t\"userId\":\"1\",\n\t\"menuUrl\":\"XXXXXXX\",\n\t\"menuName\":\"菜单名称\",\n\t\"menuCode\":\"MENU_CODE_0001\"\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{url}}/menus",
"host": [
"{{url}}"
],
"path": [
"menus"
]
}
},
"response": []
},
{
"name": "菜单-编辑",
"request": {
"method": "PUT",
"header": [
{
"key": "Content-Type",
"name": "Content-Type",
"value": "application/json",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{\n\t\"menuId\":\"1240933880494854145\",\n\t\"userId\":\"1\",\n\t\"menuUrl\":\"YYYYYY\",\n\t\"menuName\":\"菜单名称\",\n\t\"menuCode\":\"MENU_CODE_0001\"\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{url}}/menus",
"host": [
"{{url}}"
],
"path": [
"menus"
]
}
},
"response": []
},
{
"name": "菜单-删除",
"request": {
"method": "DELETE",
"header": [],
"url": {
"raw": "{{url}}/menus/:menuId",
"host": [
"{{url}}"
],
"path": [
"menus",
":menuId"
],
"variable": [
{
"key": "menuId",
"value": "1240933880494854145"
}
]
}
},
"response": []
}
],
"protocolProfileBehavior": {}
}
\ No newline at end of file
{
"id": "7d09cb0c-1f32-4fc9-8044-9a73f395fe1e",
"name": "dev:local",
"values": [
{
"key": "url",
"value": "http://127.0.0.1:8080/api/v1",
"type": "text",
"description": "",
"enabled": true
}
],
"_postman_variable_scope": "environment",
"_postman_exported_at": "2020-03-20T09:58:03.011Z",
"_postman_exported_using": "Postman/7.16.1"
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment