【问题标题】:How delete warning Unmapped target property in Mapper? [duplicate]如何在 Mapper 中删除警告未映射的目标属性? [复制]
【发布时间】:2020-04-05 18:35:38
【问题描述】:

自从我将项目从 jhipster 5.8.2 升级到 jhipster 6.5.1 后,Mapper 出现了很多警告。

我会正确对待这个警告,而不是在所有 Mapper 中添加这个属性:

(unmappedTargetPolicy = ReportingPolicy.IGNORE)

例如我有这个错误:

service\mapper\PermissionMapper.java:25: warning: Unmapped target property: "removeEntite".
Permission toEntity(PermissionDTO permissionDTO);

在我的对象权限中,我有:

@Entity
@Table(name = "permission")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class Permission implements Serializable {

private static final long serialVersionUID = 1L;

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@ManyToOne
private Profil profil;

@ManyToOne
private User user;

@ManyToMany
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
@JoinTable(name = "permission_entite",
           joinColumns = @JoinColumn(name = "permissions_id", referencedColumnName = "id"),
           inverseJoinColumns = @JoinColumn(name = "entites_id", referencedColumnName = "id"))
private Set<Entite> entites = new HashSet<>();

.... 
 public Set<Entite> getEntites() {
    return entites;
}

public Permission entites(Set<Entite> entites) {
    this.entites = entites;
    return this;
}

public Permission addEntite(Entite entite) {
    this.entites.add(entite);
    entite.getPermissions().add(this);
    return this;
}

public Permission removeEntite(Entite entite) {
    this.entites.remove(entite);
    entite.getPermissions().remove(this);
    return this;
}

public void setEntites(Set<Entite> entites) {
    this.entites = entites;
}

还有 PermissionDTO :

public class PermissionDTO implements Serializable {

private Long id;

private Long profilId;

private String profilNom;

private Long userId;

private String userLogin;

private Set<EntiteDTO> entites = new HashSet<>();

... 

public Set<EntiteDTO> getEntites() {
    return entites;
}

public void setEntites(Set<EntiteDTO> entites) {
    this.entites = entites;
}

还有映射器:

@Mapper(componentModel = "spring", uses = {ProfilMapper.class, UserMapper.class, EntiteMapper.class, })
public interface PermissionMapper extends EntityMapper <PermissionDTO, Permission> {

@Mapping(source = "profil.id", target = "profilId")
@Mapping(source = "profil.nom", target = "profilNom")

@Mapping(source = "user.id", target = "userId")
@Mapping(source = "user.login", target = "userLogin")
PermissionDTO toDto(Permission permission);

@Mapping(source = "profilId", target = "profil")

@Mapping(source = "userId", target = "user")
@Mapping(target = "entites", ignore = true)
Permission toEntity(PermissionDTO permissionDTO);

带有“ignore = true”的 ligne 不起作用。

请问你有什么想法吗?

【问题讨论】:

标签: java spring spring-data-jpa jhipster mapstruct


【解决方案1】:
@Mapper(componentModel = "spring", uses = {ProfilMapper.class, UserMapper.class, EntiteMapper.class, }, unmappedTargetPolicy = ReportingPolicy.IGNORE)

您可以在每个映射器上定义属性或使用共享映射器配置。 您的问题的解决方案在以下链接中定义

Ignore unmapped properties

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-09-15
    • 2013-04-15
    • 1970-01-01
    • 2022-10-25
    • 1970-01-01
    • 1970-01-01
    • 2020-06-13
    • 2021-11-05
    相关资源
    最近更新 更多