我有一个相当简单的映射器
/**
* Interface TicketLocationDetailsMapper that allows mapping between DTO and Domain and vice versa.
*
* @author Owen Gerig / Dev Team <br>
* created on 17 May 2022
* @since 1.0.0
*/
@Mapper(unmappedTargetPolicy = ReportingPolicy.ERROR, unmappedSourcePolicy = ReportingPolicy.ERROR)
public interface TicketLocationDetailsMapper {
/**
* Converts TicketLocationDetails domain class to DTO
*
* @param TicketLocationDetails domain class
* @return TicketLocationDetails DTO class. If null provided, would return null as well.
*/
@Mapping(source = "location", target = "locationId", nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS, nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.SET_TO_NULL)
com.ticket.dto.TicketLocationDetails TicketLocationDetailsToDto(TicketLocationDetails TicketLocationDetails);
/**
* Converts TicketLocationDetails dto class to domain
*
* @param TicketLocationDetails domain class
* @return TicketLocationDetails DTO class. If null provided, would return null as well.
*/
@Mapping(source = "locationId", target = "location", nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS, nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.SET_TO_NULL)
TicketLocationDetails TicketLocationDetailsToDomain(com.ticket.dto.TicketLocationDetails TicketLocationDetails);
/**
* Converts domain class to DTO field. dto only holds id where as domain has full object so this extra mapping is needed
*
* @param location location domain class
* @return location ID. If null provided, would return null as well.
* @since 1.0.0
*/
static UUID locationToId(TicketLocation location) {
return location.getId();
}
/**
* Converts location ID param to a new location with its id populated. dto only holds id where as domain has full object so this extra mapping is needed
*
*
* @param locationId id of the location
* @return newly created ticket TicketLocation object with its id populated. If null provided, would return null as well.
* @since 1.0.0
*/
static TicketLocation locationIdToLocation(UUID locationId) {
TicketLocation location = new TicketLocation();
location.setId(locationId);
return location;
}
}
我的域类:
@Entity
@Table(schema = "core", name = "location_details")
public class TicketLocationDetails {
@JsonView(Views.Summary.class)
private UUID id;
private String contactName;
@JsonIgnore
private TicketLocation location;
/**
* Retrieves {@code contactName}
*
* @return contactName
*/
@Column(name = "contact_email")
public String getContactName() {
return contactName;
}
/**
* Sets {@code contactName}
*
* @param contactName the {@code contactName} field
*/
public void setContactName(String contactName) {
this.contactName = contactName;
}
/**
* Retrieves {@code id}
*
* @return id
*/
@Id
@Column(name = "id")
@Type(type = "pg-uuid")
public UUID getId() {
return this.id;
}
/**
* Sets {@code id}
*
* @param id the {@code id} field
*/
public void setId(UUID id) {
this.id = id;
}
/**
* Retrieves {@code location}
*
* @return location
*/
@MapsId
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "id")
public TicketLocation getLocation() {
return this.location;
}
/**
* Sets {@code location}
*
* @param location the {@code location} field
*/
public void setLocation(TicketLocation location) {
this.location = location;
}
}
我的DTO类:
public class TicketLocationDetails {
@JsonView(Views.Summary.class)
private UUID id;
private String contactName;
private UUID locationId;
/**
* Retrieves {@code contactName}
*
* @return contactName
*/
public String getContactName() {
return contactName;
}
/**
* Sets {@code contactName}
*
* @param contactName the {@code contactName} field
*/
public void setContactName(String contactName) {
this.contactName = contactName;
}
/**
* Retrieves {@code id}
*
* @return id
*/
public UUID getId() {
return this.id;
}
/**
* Sets {@code id}
*
* @param id the {@code id} field
*/
public void setId(UUID id) {
this.id = id;
}
/**
* Retrieves {@code locationId}
*
* @return locationId
*/
public UUID getLocationId() {
return locationId;
}
/**
* Sets {@code locationId}
*
* @param id the {@code locationId} field
*/
public void setLocationId(UUID locationId) {
this.locationId = locationId;
}
}
我在mvn干净安装上收到的错误:
[错误]/C:/code报告/work/github/symphony票证/src/main/java/com/ticket/mappers/TicketLocationDetailsMapper。java:[33,48]结果类型TicketLocationDetails中的未知属性“locationId”。你是说“身份证”吗?[错误]/C:/code报告/work/github/symphony票证/src/main/java/com/ticket/mappers/TicketLocationDetailsMapper。java:[42,27]源参数中不存在名为“locationId”的属性。你是说“身份证”吗?
但是我不明白田野在哪里?
这似乎是由于类名相同,将dto更改为TicketLocationDetailsDto已解决问题
我在使用: null null 令人惊讶的是,但是toModel方法工作得很好,编译后,我在生成的源代码中看到了下面的内容: 我不知道如何修复这个映射问题。有人能帮忙吗? 下面是我的映射器:
我在一起使用mapstruct和lombok时遇到了一些问题: 我的实体和实体类: EntityMapper: 在这种配置中,它会导致编译时错误。所以我试图注释掉@映射注释。它编译了,但它将所有属性映射为空。MapSTRtEntityMapper生成的实现: 我找到了几个关于注释处理器的答案,但看看我的构建。gradle文件: 如果我编译时不使用@Mapping注解,然后使用这个注解运行,有时它会
我正在使用和,在属性映射期间我遇到了这个错误,我该如何修复它? 她的是我的 这里有一个Screenshottenter图像描述
问题1: 下面是我收到的错误,但我不知道哪里错了。 这是用于生成边缘网络的输入文件: 下面是添加报告上述问题的路由网络的代码部分。我试图绘制一个无方向的路线网络,以确保只有一条边连接两个枢纽。为了避免重复,我使用了一个if条件(if(net.getEdge(source,target)==null))来检查两个集线器之间是否已经存在一条边。如果没有,创建一个新的,如果是,什么也不做。如果我删除这个
有几种方法可以忽略mapstruct中未映射的目标属性。 对于特定方法,我们可以列出要忽略的所有属性: 是否有一种方法可以混合这些方法并忽略方法级别的所有属性,而无需明确列出所有属性?