无法映射属性,考虑declare/implement一种映射方法
Can't map property, Consider to declare/implement a mapping method
当我尝试编译我的应用程序时,它显示了这个错误,整个应用程序都是用 Jhipster 生成的。
详细说明错误:[错误] /C:/Users/user/Desktop/Devs/CURTIPIELES/curti-back/src/main/java/com/curtipieles/app/service/mapper/LeatherMapper.java:[21,16] 无法映射 属性 "com.curtipieles.app.domain.Usage leather.usage.usage”到“java.lang.String usageName”。考虑declare/implement一个映射方法:“java.lang.String map(com.curtipieles.app.domain.Usage value)”.
错误
这是我的 LeatherMapper:
@Mapper(componentModel = "spring", uses = {LeatherFamilyMapper.class, LeatherHasColorMapper.class, LeatherHasUsageMapper.class})
public interface LeatherMapper extends EntityMapper<LeatherDTO, Leather> {
@Mapping(source = "family.id", target = "familyId")
@Mapping(source = "family.name", target = "familyName")
@Mapping(source = "color.id", target = "colorId")
@Mapping(source = "color.id", target = "colorName")
@Mapping(source = "usage.id", target = "usageId")
@Mapping(source = "usage.usage", target = "usageName")
LeatherDTO toDto(Leather leather);
@Mapping(source = "familyId", target = "family")
@Mapping(source = "colorId", target = "color")
@Mapping(source = "usageId", target = "usage")
Leather toEntity(LeatherDTO leatherDTO);
default Leather fromId(Long id) {
if (id == null) {
return null;
}
Leather leather = new Leather();
leather.setId(id);
return leather;
}
}
这是我的 LeatherDTO(我没有放 Getters 和 Setters,以免把问题拉得太长)
public class LeatherDTO implements Serializable {
private Long id;
private String imageUrl;
private String name;
private String description;
private Boolean status;
private Instant creationDate;
private Boolean isNew;
private Long familyId;
private String familyName;
private Long colorId;
private String colorName;
private Long usageId;
private String usageName;
这是我的皮革 Class:
@Entity
@Table(name = "leather")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class Leather implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator =
"sequenceGenerator")
@SequenceGenerator(name = "sequenceGenerator")
private Long id;
@Column(name = "image_url")
private String imageUrl;
@Column(name = "name")
private String name;
@Column(name = "description")
private String description;
@Column(name = "status")
private Boolean status;
@Column(name = "creation_date")
private Instant creationDate;
@Column(name = "is_new")
private Boolean isNew;
@ManyToOne
@JsonIgnoreProperties(value = "leathers", allowSetters = true)
private LeatherFamily family;
@ManyToOne
@JsonIgnoreProperties(value = "leathers", allowSetters = true)
private LeatherHasColor color;
@ManyToOne
@JsonIgnoreProperties(value = "leathers", allowSetters = true)
private LeatherHasUsage usage;
这是我的 LeatherHasUsage Class:
@Entity
@Table(name = "leather_has_usage")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class LeatherHasUsage implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator =
"sequenceGenerator")
@SequenceGenerator(name = "sequenceGenerator")
private Long id;
@Column(name = "status")
private Boolean status;
@ManyToOne
@JsonIgnoreProperties(value = "leatherHasUsages", allowSetters = true)
private Usage usage;
// jhipster-needle-entity-add-field - JHipster will add fields here
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Boolean isStatus() {
return status;
}
public LeatherHasUsage status(Boolean status) {
this.status = status;
return this;
}
这是我的 LeatherHasColor class:
@Entity
@Table(name = "leather_has_color")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class LeatherHasColor implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequenceGenerator")
@SequenceGenerator(name = "sequenceGenerator")
private Long id;
@Column(name = "status")
private Boolean status;
@ManyToOne
@JsonIgnoreProperties(value = "leatherHasColors", allowSetters = true)
private Color color;
这是我的 LeatherFamily class
@Entity
@Table(name = "leather_family")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class LeatherFamily implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator =
"sequenceGenerator")
@SequenceGenerator(name = "sequenceGenerator")
private Long id;
@Column(name = "image_url")
private String imageUrl;
@Column(name = "name")
private String name;
@Column(name = "description")
private String description;
@Column(name = "status")
private Boolean status;
@Column(name = "is_new")
private Boolean isNew;
@Column(name = "creation_date")
private Instant creationDate;
这就是问题的解决方案
You change "usage.usage" to "usage.usage.usage", and likely also change "usage.id" to "usage.usage.id", since you seemingly forgot you have an extra level of object, and do similar change for color, and your code should be all fixed. -
当我尝试编译我的应用程序时,它显示了这个错误,整个应用程序都是用 Jhipster 生成的。
详细说明错误:[错误] /C:/Users/user/Desktop/Devs/CURTIPIELES/curti-back/src/main/java/com/curtipieles/app/service/mapper/LeatherMapper.java:[21,16] 无法映射 属性 "com.curtipieles.app.domain.Usage leather.usage.usage”到“java.lang.String usageName”。考虑declare/implement一个映射方法:“java.lang.String map(com.curtipieles.app.domain.Usage value)”.
错误
这是我的 LeatherMapper:
@Mapper(componentModel = "spring", uses = {LeatherFamilyMapper.class, LeatherHasColorMapper.class, LeatherHasUsageMapper.class})
public interface LeatherMapper extends EntityMapper<LeatherDTO, Leather> {
@Mapping(source = "family.id", target = "familyId")
@Mapping(source = "family.name", target = "familyName")
@Mapping(source = "color.id", target = "colorId")
@Mapping(source = "color.id", target = "colorName")
@Mapping(source = "usage.id", target = "usageId")
@Mapping(source = "usage.usage", target = "usageName")
LeatherDTO toDto(Leather leather);
@Mapping(source = "familyId", target = "family")
@Mapping(source = "colorId", target = "color")
@Mapping(source = "usageId", target = "usage")
Leather toEntity(LeatherDTO leatherDTO);
default Leather fromId(Long id) {
if (id == null) {
return null;
}
Leather leather = new Leather();
leather.setId(id);
return leather;
}
}
这是我的 LeatherDTO(我没有放 Getters 和 Setters,以免把问题拉得太长)
public class LeatherDTO implements Serializable {
private Long id;
private String imageUrl;
private String name;
private String description;
private Boolean status;
private Instant creationDate;
private Boolean isNew;
private Long familyId;
private String familyName;
private Long colorId;
private String colorName;
private Long usageId;
private String usageName;
这是我的皮革 Class:
@Entity
@Table(name = "leather")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class Leather implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator =
"sequenceGenerator")
@SequenceGenerator(name = "sequenceGenerator")
private Long id;
@Column(name = "image_url")
private String imageUrl;
@Column(name = "name")
private String name;
@Column(name = "description")
private String description;
@Column(name = "status")
private Boolean status;
@Column(name = "creation_date")
private Instant creationDate;
@Column(name = "is_new")
private Boolean isNew;
@ManyToOne
@JsonIgnoreProperties(value = "leathers", allowSetters = true)
private LeatherFamily family;
@ManyToOne
@JsonIgnoreProperties(value = "leathers", allowSetters = true)
private LeatherHasColor color;
@ManyToOne
@JsonIgnoreProperties(value = "leathers", allowSetters = true)
private LeatherHasUsage usage;
这是我的 LeatherHasUsage Class:
@Entity
@Table(name = "leather_has_usage")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class LeatherHasUsage implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator =
"sequenceGenerator")
@SequenceGenerator(name = "sequenceGenerator")
private Long id;
@Column(name = "status")
private Boolean status;
@ManyToOne
@JsonIgnoreProperties(value = "leatherHasUsages", allowSetters = true)
private Usage usage;
// jhipster-needle-entity-add-field - JHipster will add fields here
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Boolean isStatus() {
return status;
}
public LeatherHasUsage status(Boolean status) {
this.status = status;
return this;
}
这是我的 LeatherHasColor class:
@Entity
@Table(name = "leather_has_color")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class LeatherHasColor implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequenceGenerator")
@SequenceGenerator(name = "sequenceGenerator")
private Long id;
@Column(name = "status")
private Boolean status;
@ManyToOne
@JsonIgnoreProperties(value = "leatherHasColors", allowSetters = true)
private Color color;
这是我的 LeatherFamily class
@Entity
@Table(name = "leather_family")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class LeatherFamily implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator =
"sequenceGenerator")
@SequenceGenerator(name = "sequenceGenerator")
private Long id;
@Column(name = "image_url")
private String imageUrl;
@Column(name = "name")
private String name;
@Column(name = "description")
private String description;
@Column(name = "status")
private Boolean status;
@Column(name = "is_new")
private Boolean isNew;
@Column(name = "creation_date")
private Instant creationDate;
这就是问题的解决方案
You change "usage.usage" to "usage.usage.usage", and likely also change "usage.id" to "usage.usage.id", since you seemingly forgot you have an extra level of object, and do similar change for color, and your code should be all fixed. -