我尝试映射对象的引用,但出现错误。
我的DTO对象:
public class UserDetails {
//another fields
private String role;
// getter and setter
我的用户实体对象:
@Table
@Entity
public class User implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "user_id", nullable = false)
private int userId;
@Transient
private Role role;
// getter and setter
我的角色实体:
@Table
@Entity
public class Role implements GrantedAuthority {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "role_id", nullable = false)
private int roleId;
@OneToOne(targetEntity = User.class, fetch = FetchType.LAZY, cascade = { CascadeType.PERSIST, CascadeType.REMOVE })
@JoinColumn(name = "user", referencedColumnName = "user_id", nullable = false)
private User user;
...
我的MapStruct介面:
@Mapper
public interface UserMapper {
@Mapping(target = "password", ignore = true)
UserDetails mapUser(User user);
@Mappings({
@Mapping(source = "role", target = "role.name"),
@Mapping(target = "password", ignore = true),
@Mapping(target = "firstLogin", ignore = true)
})
User mapUserDetails(UserDetails userDetails);
When i run mvn clean install
我收到此错误:
Error:(13,17) java: Can't map property "java.util.List<com.test.core.entities.Role> role" to "java.lang.String role". Consider to declare/implement a mapping method: "java.lang.String map(java.util.List<com.test.core.entities.Role> value)".