diff --git a/assets/src/main/java/io/leafage/basic/assets/service/impl/CategoryServiceImpl.java b/assets/src/main/java/io/leafage/basic/assets/service/impl/CategoryServiceImpl.java index ed063831..121ce401 100644 --- a/assets/src/main/java/io/leafage/basic/assets/service/impl/CategoryServiceImpl.java +++ b/assets/src/main/java/io/leafage/basic/assets/service/impl/CategoryServiceImpl.java @@ -22,7 +22,7 @@ import io.leafage.basic.assets.repository.PostRepository; import io.leafage.basic.assets.service.CategoryService; import io.leafage.basic.assets.vo.CategoryVO; -import org.springframework.beans.BeanUtils; +import org.springframework.cglib.beans.BeanCopier; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; @@ -75,21 +75,25 @@ public boolean exist(String name) { } @Override - public CategoryVO create(CategoryDTO categoryDTO) { + public CategoryVO create(CategoryDTO dto) { Category category = new Category(); - BeanUtils.copyProperties(categoryDTO, category); + BeanCopier copier = BeanCopier.create(CategoryDTO.class, Category.class, false); + copier.copy(dto, category, null); + category = categoryRepository.saveAndFlush(category); return this.convertOuter(category); } @Override - public CategoryVO modify(Long id, CategoryDTO categoryDTO) { + public CategoryVO modify(Long id, CategoryDTO dto) { Assert.notNull(id, "category id must not be null."); Category category = categoryRepository.findById(id).orElse(null); if (category == null) { return null; } - BeanUtils.copyProperties(categoryDTO, category); + BeanCopier copier = BeanCopier.create(CategoryDTO.class, Category.class, false); + copier.copy(dto, category, null); + category = categoryRepository.save(category); return this.convertOuter(category); } @@ -104,14 +108,15 @@ public void remove(Long id) { /** * 对象转换为输出结果对象 * - * @param info 信息 + * @param category 信息 * @return 输出转换后的vo对象 */ - private CategoryVO convertOuter(Category info) { + private CategoryVO convertOuter(Category category) { CategoryVO vo = new CategoryVO(); - BeanUtils.copyProperties(info, vo); + BeanCopier copier = BeanCopier.create(Category.class, CategoryVO.class, false); + copier.copy(category, vo, null); - long count = postRepository.countByCategoryId(info.getId()); + long count = postRepository.countByCategoryId(category.getId()); vo.setCount(count); return vo; } diff --git a/assets/src/main/java/io/leafage/basic/assets/service/impl/CommentServiceImpl.java b/assets/src/main/java/io/leafage/basic/assets/service/impl/CommentServiceImpl.java index c61438ea..c3f088f3 100644 --- a/assets/src/main/java/io/leafage/basic/assets/service/impl/CommentServiceImpl.java +++ b/assets/src/main/java/io/leafage/basic/assets/service/impl/CommentServiceImpl.java @@ -23,7 +23,7 @@ import io.leafage.basic.assets.repository.PostStatisticsRepository; import io.leafage.basic.assets.service.CommentService; import io.leafage.basic.assets.vo.CommentVO; -import org.springframework.beans.BeanUtils; +import org.springframework.cglib.beans.BeanCopier; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.stereotype.Service; @@ -68,9 +68,11 @@ public List replies(Long replier) { @Transactional(rollbackFor = Exception.class) @Override - public CommentVO create(CommentDTO commentDTO) { + public CommentVO create(CommentDTO dto) { Comment comment = new Comment(); - BeanUtils.copyProperties(commentDTO, comment); + BeanCopier copier = BeanCopier.create(CommentDTO.class, Comment.class, false); + copier.copy(dto, comment, null); + comment = commentRepository.saveAndFlush(comment); // 添加关联帖子的评论数 this.postStatisticsRepository.increaseComment(comment.getPostId()); @@ -85,7 +87,8 @@ public CommentVO create(CommentDTO commentDTO) { */ private CommentVO convertOuter(Comment comment) { CommentVO vo = new CommentVO(); - BeanUtils.copyProperties(comment, vo); + BeanCopier copier = BeanCopier.create(Comment.class, CommentVO.class, false); + copier.copy(comment, vo, null); Long count = commentRepository.countByReplier(comment.getId()); vo.setCount(count); diff --git a/assets/src/main/java/io/leafage/basic/assets/service/impl/PostStatisticsServiceImpl.java b/assets/src/main/java/io/leafage/basic/assets/service/impl/PostStatisticsServiceImpl.java index dc67c9ab..bb2ac459 100644 --- a/assets/src/main/java/io/leafage/basic/assets/service/impl/PostStatisticsServiceImpl.java +++ b/assets/src/main/java/io/leafage/basic/assets/service/impl/PostStatisticsServiceImpl.java @@ -22,7 +22,7 @@ import io.leafage.basic.assets.repository.PostStatisticsRepository; import io.leafage.basic.assets.service.PostStatisticsService; import io.leafage.basic.assets.vo.PostStatisticsVO; -import org.springframework.beans.BeanUtils; +import org.springframework.cglib.beans.BeanCopier; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.stereotype.Service; @@ -47,9 +47,11 @@ public Page retrieve(int page, int size) { } @Override - public PostStatisticsVO create(PostStatisticsDTO postStatisticsDTO) { + public PostStatisticsVO create(PostStatisticsDTO dto) { PostStatistics postStatistics = new PostStatistics(); - BeanUtils.copyProperties(postStatisticsDTO, postStatistics); + BeanCopier copier = BeanCopier.create(PostStatisticsDTO.class, PostStatistics.class, false); + copier.copy(dto, postStatistics, null); + postStatistics = postStatisticsRepository.saveAndFlush(postStatistics); return this.convertOuter(postStatistics); } @@ -62,7 +64,8 @@ public PostStatisticsVO create(PostStatisticsDTO postStatisticsDTO) { */ private PostStatisticsVO convertOuter(PostStatistics postStatistics) { PostStatisticsVO vo = new PostStatisticsVO(); - BeanUtils.copyProperties(postStatistics, vo); + BeanCopier copier = BeanCopier.create(PostStatistics.class, PostStatisticsVO.class, false); + copier.copy(postStatistics, vo, null); return vo; } diff --git a/assets/src/main/java/io/leafage/basic/assets/service/impl/PostsServiceImpl.java b/assets/src/main/java/io/leafage/basic/assets/service/impl/PostsServiceImpl.java index 7eb0c65d..a753d292 100644 --- a/assets/src/main/java/io/leafage/basic/assets/service/impl/PostsServiceImpl.java +++ b/assets/src/main/java/io/leafage/basic/assets/service/impl/PostsServiceImpl.java @@ -27,7 +27,7 @@ import io.leafage.basic.assets.service.PostsService; import io.leafage.basic.assets.vo.PostContentVO; import io.leafage.basic.assets.vo.PostVO; -import org.springframework.beans.BeanUtils; +import org.springframework.cglib.beans.BeanCopier; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; @@ -90,7 +90,9 @@ public PostContentVO details(Long id) { PostVO vo = this.convertOuter(post); PostContentVO postsContentVO = new PostContentVO(); - BeanUtils.copyProperties(vo, postsContentVO); + BeanCopier copier = BeanCopier.create(PostVO.class, PostContentVO.class, false); + copier.copy(vo, postsContentVO, null); + postsContentVO.setPostsId(post.getId()); // 获取内容详情 PostContent postContent = postContentRepository.getByPostId(id); @@ -121,10 +123,12 @@ public boolean exist(String title) { @Transactional(rollbackFor = Exception.class) @Override - public PostVO create(PostDTO postDTO) { + public PostVO create(PostDTO dto) { Post post = new Post(); - BeanUtils.copyProperties(postDTO, post); - post.setTags(postDTO.getTags().toString()); + BeanCopier copier = BeanCopier.create(PostDTO.class, Post.class, false); + copier.copy(dto, post, null); + + post.setTags(dto.getTags().toString()); // 保存并立即刷盘 post = postRepository.saveAndFlush(post); //保存帖子内容 @@ -133,22 +137,24 @@ public PostVO create(PostDTO postDTO) { postContent = new PostContent(); } postContent.setPostId(post.getId()); - postContent.setContent(postDTO.getContent()); + postContent.setContent(dto.getContent()); postContentRepository.saveAndFlush(postContent); //转换结果 return this.convertOuter(post); } @Override - public PostVO modify(Long id, PostDTO postDTO) { + public PostVO modify(Long id, PostDTO dto) { Assert.notNull(id, "post id must not be null."); //查询基本信息 Post post = postRepository.findById(id).orElse(null); if (post == null) { return null; } - BeanUtils.copyProperties(postDTO, post); - post.setTags(postDTO.getTags().toString()); + BeanCopier copier = BeanCopier.create(PostDTO.class, Post.class, false); + copier.copy(dto, post, null); + + post.setTags(dto.getTags().toString()); post = postRepository.save(post); //保存文章内容 @@ -156,7 +162,7 @@ public PostVO modify(Long id, PostDTO postDTO) { if (postContent == null) { postContent = new PostContent(); } - postContent.setContent(postDTO.getContent()); + postContent.setContent(dto.getContent()); postContentRepository.save(postContent); //转换结果 return this.convertOuter(post); @@ -177,7 +183,9 @@ public void remove(Long id) { */ private PostVO convertOuter(Post post) { PostVO vo = new PostVO(); - BeanUtils.copyProperties(post, vo); + BeanCopier copier = BeanCopier.create(Post.class, PostVO.class, false); + copier.copy(post, vo, null); + // 转换 tags if (StringUtils.hasText(post.getTags())) { String tags = post.getTags().substring(1, post.getTags().length() - 1) diff --git a/hypervisor/src/main/java/io/leafage/basic/hypervisor/service/impl/AccessLogServiceImpl.java b/hypervisor/src/main/java/io/leafage/basic/hypervisor/service/impl/AccessLogServiceImpl.java index 59922326..afed81e3 100644 --- a/hypervisor/src/main/java/io/leafage/basic/hypervisor/service/impl/AccessLogServiceImpl.java +++ b/hypervisor/src/main/java/io/leafage/basic/hypervisor/service/impl/AccessLogServiceImpl.java @@ -22,7 +22,7 @@ import io.leafage.basic.hypervisor.repository.AccessLogRepository; import io.leafage.basic.hypervisor.service.AccessLogService; import io.leafage.basic.hypervisor.vo.AccessLogVO; -import org.springframework.beans.BeanUtils; +import org.springframework.cglib.beans.BeanCopier; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.stereotype.Service; @@ -47,16 +47,19 @@ public Page retrieve(int page, int size) { } @Override - public AccessLogVO create(AccessLogDTO accessLogDTO) { + public AccessLogVO create(AccessLogDTO dto) { AccessLog accessLog = new AccessLog(); - BeanUtils.copyProperties(accessLogDTO, accessLog); + BeanCopier copier = BeanCopier.create(AccessLogDTO.class, AccessLog.class, false); + copier.copy(dto, accessLog, null); + accessLogRepository.saveAndFlush(accessLog); return this.convert(accessLog); } private AccessLogVO convert(AccessLog accessLog) { AccessLogVO vo = new AccessLogVO(); - BeanUtils.copyProperties(accessLog, vo); + BeanCopier copier = BeanCopier.create(AccessLog.class, AccessLogVO.class, false); + copier.copy(accessLog, vo, null); return vo; } } diff --git a/hypervisor/src/main/java/io/leafage/basic/hypervisor/service/impl/DictionaryServiceImpl.java b/hypervisor/src/main/java/io/leafage/basic/hypervisor/service/impl/DictionaryServiceImpl.java index 500decb5..d026c1c7 100644 --- a/hypervisor/src/main/java/io/leafage/basic/hypervisor/service/impl/DictionaryServiceImpl.java +++ b/hypervisor/src/main/java/io/leafage/basic/hypervisor/service/impl/DictionaryServiceImpl.java @@ -22,7 +22,7 @@ import io.leafage.basic.hypervisor.repository.DictionaryRepository; import io.leafage.basic.hypervisor.service.DictionaryService; import io.leafage.basic.hypervisor.vo.DictionaryVO; -import org.springframework.beans.BeanUtils; +import org.springframework.cglib.beans.BeanCopier; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.stereotype.Service; @@ -74,9 +74,11 @@ public boolean exist(String name) { } @Override - public DictionaryVO create(DictionaryDTO dictionaryDTO) { + public DictionaryVO create(DictionaryDTO dto) { Dictionary dictionary = new Dictionary(); - BeanUtils.copyProperties(dictionaryDTO, dictionary); + BeanCopier copier = BeanCopier.create(DictionaryDTO.class, Dictionary.class, false); + copier.copy(dto, dictionary, null); + dictionaryRepository.saveAndFlush(dictionary); return this.convert(dictionary); @@ -90,7 +92,8 @@ public DictionaryVO create(DictionaryDTO dictionaryDTO) { */ private DictionaryVO convert(Dictionary dictionary) { DictionaryVO vo = new DictionaryVO(); - BeanUtils.copyProperties(dictionary, vo); + BeanCopier copier = BeanCopier.create(Dictionary.class, DictionaryVO.class, false); + copier.copy(dictionary, vo, null); return vo; } } diff --git a/hypervisor/src/main/java/io/leafage/basic/hypervisor/service/impl/GroupServiceImpl.java b/hypervisor/src/main/java/io/leafage/basic/hypervisor/service/impl/GroupServiceImpl.java index 7b383a1f..e616b6bc 100644 --- a/hypervisor/src/main/java/io/leafage/basic/hypervisor/service/impl/GroupServiceImpl.java +++ b/hypervisor/src/main/java/io/leafage/basic/hypervisor/service/impl/GroupServiceImpl.java @@ -22,7 +22,7 @@ import io.leafage.basic.hypervisor.repository.GroupRepository; import io.leafage.basic.hypervisor.service.GroupService; import io.leafage.basic.hypervisor.vo.GroupVO; -import org.springframework.beans.BeanUtils; +import org.springframework.cglib.beans.BeanCopier; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; @@ -74,20 +74,25 @@ public List tree() { } @Override - public GroupVO create(GroupDTO groupDTO) { + public GroupVO create(GroupDTO dto) { Group group = new Group(); - BeanUtils.copyProperties(groupDTO, group); + BeanCopier copier = BeanCopier.create(GroupDTO.class, Group.class, false); + copier.copy(dto, group, null); + group = groupRepository.saveAndFlush(group); return this.convertOuter(group); } @Override - public GroupVO modify(Long id, GroupDTO groupDTO) { + public GroupVO modify(Long id, GroupDTO dto) { Assert.notNull(id, "group id must not be null."); Group group = groupRepository.findById(id).orElse(null); if (group == null) { throw new NoSuchElementException("当前操作数据不存在..."); } + BeanCopier copier = BeanCopier.create(GroupDTO.class, Group.class, false); + copier.copy(dto, group, null); + group = groupRepository.save(group); return this.convertOuter(group); } @@ -105,11 +110,13 @@ public void remove(Long id) { * @return 结果对象 */ private GroupVO convertOuter(Group group) { - GroupVO groupVO = new GroupVO(); - BeanUtils.copyProperties(group, groupVO); + GroupVO vo = new GroupVO(); + BeanCopier copier = BeanCopier.create(Group.class, GroupVO.class, false); + copier.copy(group, vo, null); + long count = groupMembersRepository.countByGroupIdAndEnabledTrue(group.getId()); - groupVO.setCount(count); - return groupVO; + vo.setCount(count); + return vo; } } diff --git a/hypervisor/src/main/java/io/leafage/basic/hypervisor/service/impl/MessageServiceImpl.java b/hypervisor/src/main/java/io/leafage/basic/hypervisor/service/impl/MessageServiceImpl.java index 82edad1c..ab49544a 100644 --- a/hypervisor/src/main/java/io/leafage/basic/hypervisor/service/impl/MessageServiceImpl.java +++ b/hypervisor/src/main/java/io/leafage/basic/hypervisor/service/impl/MessageServiceImpl.java @@ -22,7 +22,7 @@ import io.leafage.basic.hypervisor.repository.MessageRepository; import io.leafage.basic.hypervisor.service.MessageService; import io.leafage.basic.hypervisor.vo.MessageVO; -import org.springframework.beans.BeanUtils; +import org.springframework.cglib.beans.BeanCopier; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; @@ -58,9 +58,11 @@ public MessageVO fetch(Long id) { } @Override - public MessageVO create(MessageDTO messageDTO) { + public MessageVO create(MessageDTO dto) { Message message = new Message(); - BeanUtils.copyProperties(messageDTO, message); + BeanCopier copier = BeanCopier.create(MessageDTO.class, Message.class, false); + copier.copy(dto, message, null); + messageRepository.saveAndFlush(message); return this.convertOuter(message); } @@ -71,8 +73,9 @@ public MessageVO create(MessageDTO messageDTO) { * @return ExampleMatcher */ private MessageVO convertOuter(Message message) { - MessageVO messageVO = new MessageVO(); - BeanUtils.copyProperties(message, messageVO); - return messageVO; + MessageVO vo = new MessageVO(); + BeanCopier copier = BeanCopier.create(Message.class, MessageVO.class, false); + copier.copy(message, vo, null); + return vo; } } diff --git a/hypervisor/src/main/java/io/leafage/basic/hypervisor/service/impl/PrivilegeServiceImpl.java b/hypervisor/src/main/java/io/leafage/basic/hypervisor/service/impl/PrivilegeServiceImpl.java index 75786ee4..97f61cb1 100644 --- a/hypervisor/src/main/java/io/leafage/basic/hypervisor/service/impl/PrivilegeServiceImpl.java +++ b/hypervisor/src/main/java/io/leafage/basic/hypervisor/service/impl/PrivilegeServiceImpl.java @@ -22,7 +22,7 @@ import io.leafage.basic.hypervisor.repository.RolePrivilegesRepository; import io.leafage.basic.hypervisor.service.PrivilegeService; import io.leafage.basic.hypervisor.vo.PrivilegeVO; -import org.springframework.beans.BeanUtils; +import org.springframework.cglib.beans.BeanCopier; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; @@ -66,21 +66,25 @@ public List tree() { } @Override - public PrivilegeVO create(PrivilegeDTO privilegeDTO) { + public PrivilegeVO create(PrivilegeDTO dto) { Privilege privilege = new Privilege(); - BeanUtils.copyProperties(privilegeDTO, privilege); + BeanCopier copier = BeanCopier.create(PrivilegeDTO.class, Privilege.class, false); + copier.copy(dto, privilege, null); + privilege = privilegeRepository.saveAndFlush(privilege); return this.convertOuter(privilege); } @Override - public PrivilegeVO modify(Long id, PrivilegeDTO privilegeDTO) { + public PrivilegeVO modify(Long id, PrivilegeDTO dto) { Assert.notNull(id, "privilege id must not be null."); Privilege privilege = privilegeRepository.findById(id).orElse(null); if (privilege == null) { throw new NoSuchElementException("当前操作数据不存在..."); } - BeanUtils.copyProperties(privilegeDTO, privilege); + BeanCopier copier = BeanCopier.create(PrivilegeDTO.class, Privilege.class, false); + copier.copy(dto, privilege, null); + privilege = privilegeRepository.save(privilege); return this.convertOuter(privilege); } @@ -99,9 +103,10 @@ public void remove(Long id) { * @return 结果对象 */ private PrivilegeVO convertOuter(Privilege privilege) { - PrivilegeVO privilegeVO = new PrivilegeVO(); - BeanUtils.copyProperties(privilege, privilegeVO); - return privilegeVO; + PrivilegeVO vo = new PrivilegeVO(); + BeanCopier copier = BeanCopier.create(Privilege.class, PrivilegeVO.class, false); + copier.copy(privilege, vo, null); + return vo; } /** diff --git a/hypervisor/src/main/java/io/leafage/basic/hypervisor/service/impl/RegionServiceImpl.java b/hypervisor/src/main/java/io/leafage/basic/hypervisor/service/impl/RegionServiceImpl.java index 83aaf088..1060626f 100644 --- a/hypervisor/src/main/java/io/leafage/basic/hypervisor/service/impl/RegionServiceImpl.java +++ b/hypervisor/src/main/java/io/leafage/basic/hypervisor/service/impl/RegionServiceImpl.java @@ -22,7 +22,7 @@ import io.leafage.basic.hypervisor.repository.RegionRepository; import io.leafage.basic.hypervisor.service.RegionService; import io.leafage.basic.hypervisor.vo.RegionVO; -import org.springframework.beans.BeanUtils; +import org.springframework.cglib.beans.BeanCopier; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.stereotype.Service; @@ -74,21 +74,25 @@ public boolean exist(String name) { } @Override - public RegionVO create(RegionDTO regionDTO) { + public RegionVO create(RegionDTO dto) { Region region = new Region(); - BeanUtils.copyProperties(regionDTO, region); + BeanCopier copier = BeanCopier.create(RegionDTO.class, Region.class, false); + copier.copy(dto, region, null); + regionRepository.saveAndFlush(region); return this.convertOuter(region); } @Override - public RegionVO modify(Long id, RegionDTO regionDTO) { + public RegionVO modify(Long id, RegionDTO dto) { Assert.notNull(id, "region id must not be null."); Region region = regionRepository.findById(id).orElse(null); if (region == null) { return null; } - BeanUtils.copyProperties(regionDTO, region); + BeanCopier copier = BeanCopier.create(RegionDTO.class, Region.class, false); + copier.copy(dto, region, null); + regionRepository.save(region); return this.convertOuter(region); } @@ -107,7 +111,8 @@ public void remove(Long id) { */ private RegionVO convertOuter(Region region) { RegionVO vo = new RegionVO(); - BeanUtils.copyProperties(region, vo); + BeanCopier copier = BeanCopier.create(Region.class, RegionVO.class, false); + copier.copy(region, vo, null); if (region.getSuperiorId() != null) { Optional optional = regionRepository.findById(region.getSuperiorId()); diff --git a/hypervisor/src/main/java/io/leafage/basic/hypervisor/service/impl/RoleServiceImpl.java b/hypervisor/src/main/java/io/leafage/basic/hypervisor/service/impl/RoleServiceImpl.java index 6bf687f2..cb9c4f07 100644 --- a/hypervisor/src/main/java/io/leafage/basic/hypervisor/service/impl/RoleServiceImpl.java +++ b/hypervisor/src/main/java/io/leafage/basic/hypervisor/service/impl/RoleServiceImpl.java @@ -22,7 +22,7 @@ import io.leafage.basic.hypervisor.repository.RoleRepository; import io.leafage.basic.hypervisor.service.RoleService; import io.leafage.basic.hypervisor.vo.RoleVO; -import org.springframework.beans.BeanUtils; +import org.springframework.cglib.beans.BeanCopier; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; @@ -85,21 +85,25 @@ public RoleVO fetch(Long id) { } @Override - public RoleVO create(RoleDTO roleDTO) { + public RoleVO create(RoleDTO dto) { Role role = new Role(); - BeanUtils.copyProperties(roleDTO, role); + BeanCopier copier = BeanCopier.create(RoleDTO.class, Role.class, false); + copier.copy(dto, role, null); + role = roleRepository.saveAndFlush(role); return this.convertOuter(role); } @Override - public RoleVO modify(Long id, RoleDTO roleDTO) { + public RoleVO modify(Long id, RoleDTO dto) { Assert.notNull(id, "role id must not be null."); Role role = roleRepository.findById(id).orElse(null); if (role == null) { throw new NoSuchElementException("当前操作数据不存在..."); } - BeanUtils.copyProperties(roleDTO, role); + BeanCopier copier = BeanCopier.create(RoleDTO.class, Role.class, false); + copier.copy(dto, role, null); + role = roleRepository.save(role); return this.convertOuter(role); } @@ -113,15 +117,17 @@ public void remove(Long id) { /** * 转换对象 * - * @param info 基础对象 + * @param role {@link Role} * @return 结果对象 */ - private RoleVO convertOuter(Role info) { - RoleVO roleVO = new RoleVO(); - BeanUtils.copyProperties(info, roleVO); - long count = roleMembersRepository.countByRoleIdAndEnabledTrue(info.getId()); - roleVO.setCount(count); - return roleVO; + private RoleVO convertOuter(Role role) { + RoleVO vo = new RoleVO(); + BeanCopier copier = BeanCopier.create(Role.class, RoleVO.class, false); + copier.copy(role, vo, null); + + long count = roleMembersRepository.countByRoleIdAndEnabledTrue(role.getId()); + vo.setCount(count); + return vo; } } diff --git a/hypervisor/src/main/java/io/leafage/basic/hypervisor/service/impl/UserServiceImpl.java b/hypervisor/src/main/java/io/leafage/basic/hypervisor/service/impl/UserServiceImpl.java index 0f16244b..215fc6a3 100644 --- a/hypervisor/src/main/java/io/leafage/basic/hypervisor/service/impl/UserServiceImpl.java +++ b/hypervisor/src/main/java/io/leafage/basic/hypervisor/service/impl/UserServiceImpl.java @@ -21,7 +21,7 @@ import io.leafage.basic.hypervisor.repository.UserRepository; import io.leafage.basic.hypervisor.service.UserService; import io.leafage.basic.hypervisor.vo.UserVO; -import org.springframework.beans.BeanUtils; +import org.springframework.cglib.beans.BeanCopier; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; @@ -67,21 +67,25 @@ public boolean exist(String username) { } @Override - public UserVO create(UserDTO userDTO) { + public UserVO create(UserDTO dto) { User user = new User(); - BeanUtils.copyProperties(userDTO, user); + BeanCopier copier = BeanCopier.create(UserDTO.class, User.class, false); + copier.copy(dto, user, null); + user = userRepository.saveAndFlush(user); return this.convertOuter(user); } @Override - public UserVO modify(Long id, UserDTO userDTO) { + public UserVO modify(Long id, UserDTO dto) { Assert.notNull(id, "role id must not be null."); User user = userRepository.findById(id).orElse(null); if (user == null) { return null; } - BeanUtils.copyProperties(userDTO, user); + BeanCopier copier = BeanCopier.create(UserDTO.class, User.class, false); + copier.copy(dto, user, null); + user = userRepository.save(user); return this.convertOuter(user); } @@ -98,9 +102,11 @@ public void remove(Long id) { * @return ExampleMatcher */ private UserVO convertOuter(User user) { - UserVO userVO = new UserVO(); - BeanUtils.copyProperties(user, userVO); - return userVO; + UserVO vo = new UserVO(); + BeanCopier copier = BeanCopier.create(User.class, UserVO.class, false); + copier.copy(user, vo, null); + + return vo; } }