@mapping@mapper错误不存在源参数

pokxtpni  于 2021-06-30  发布在  Java
关注(0)|答案(1)|浏览(403)

我一直在把我的项目从spring转移到springboot,并引入了嵌入式tomcat有一些修改我必须做的只有我在我的老项目i have mapper interface中面临的问题。
当我编译这个项目的时候,它开始给出错误
错误:(12,5)java:源参数中不存在名为“schoolid”的属性。
我已经搜索了很多关于它的一些说lombok依赖放置在pom我尝试放置它之前和之后的Map结构依赖,但错误仍然在这里
下面是我的课

下面是我面临的错误

bf1o4zei

bf1o4zei1#

@shermeen你能分享你的配置代码吗?
所以我们交叉验证。我还是加了这个例子,请检查一下。

结构

entitymapper.java文件

public interface EntityMapper<D, E> {
  E toEntity(D dto);
  D toDTO(E entity);
  List<E> toEntity(List<D> dtoList);
  List<D> toDTO(List<E> entityList);
}

用户Map器.java

import com.ecommerce.auth_service.domain.external_db.User;
import com.ecommerce.auth_service.domain.external_db.dto.UserDTO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;

import java.util.UUID;

@Mapper(componentModel = "spring", uses = {UserMapper.class})
public interface UserMapper extends EntityMapper<UserDTO, User> {

  @Mapping(source = "user_id", target = "user")

  default User fromId(UUID id) {
    if (id == null)
      return null;
    User user = new User();
    user.setUserId(id);
    return user;
  }
}

usermapperimpl.java文件

import com.ecommerce.auth_service.domain.external_db.User;
import com.ecommerce.auth_service.domain.external_db.dto.UserDTO;
import com.ecommerce.auth_service.domain.external_db.mapper.UserMapper;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

@Component
public class UserMapperImpl implements UserMapper {
  @Override
  public User toEntity(UserDTO dto) {
    if (dto == null)
      return null;

    User user = new User();
    user.setUserId(dto.getUserId());
    user.setUsername(dto.getUsername());
    user.setEmail(dto.getEmail());
    user.setPassword(dto.getPassword());
    user.setPhoneNo(dto.getPhoneNumber());
    user.setStatus(dto.getStatus());
    user.setStore(dto.getStoreId());
    user.setAuthority(dto.getAuthority());
    user.setPrivileges(dto.getAuthority().getPrivileges());

    return user;
  }

  @Override
  public UserDTO toDTO(User entity) {
    if (entity == null) {
      return null;
    }

    UserDTO userDTO = new UserDTO();

    userDTO.setUserId(entity.getUserId());
    userDTO.setUsername(entity.getUsername());
    userDTO.setEmail(entity.getEmail());
    userDTO.setPassword(entity.getPassword());
    userDTO.setPhoneNumber(entity.getPhoneNo());
    userDTO.setStatus(entity.getStatus());
    userDTO.setStoreId(entity.getStore());

    entity.getAuthority().setPrivileges(entity.getPrivileges());
    userDTO.setAuthority(entity.getAuthority());

    userDTO.setCreatedBy(entity.getCreatedBy());
    userDTO.setCreatedDate(entity.getCreatedDate());
    userDTO.setModifiedBy(entity.getModifiedBy());
    userDTO.setModifiedDate(entity.getModifiedDate());

    return userDTO;
  }

  @Override
  public List<User> toEntity(List<UserDTO> dtoList) {
    if (dtoList == null || dtoList.isEmpty())
      return null;
    List<User> userList = new ArrayList<>(dtoList.size());
    for (UserDTO userDTO : dtoList) {
      userList.add(toEntity(userDTO));
    }
    return userList;
  }

  @Override
  public List<UserDTO> toDTO(List<User> entityList) {
    if (entityList == null)
      return null;
    List<UserDTO> userDTOList = new ArrayList<>(entityList.size());
    for (User user : entityList) {
      userDTOList.add(toDTO(user));
    }
    return userDTOList;
  }
}

相关问题