我想把userdto转换成user
用户收件人:
public class UserDto {
private String username;
private String password;
private Set<RoleDto> roles;
//getters and setters
}
角色:
public class RoleDto {
private String name;
//getters and setters
}
用户:
public class User {
private String username;
private String password;
private Set<Role>;
//getters and setters
}
角色:
public enum Role {
private String name;
//getters
}
我的Map器类:
@Mapper(componentModel = "spring")
public interface UserMapper {
UserDto toDto(User user);
User fromDto(UserDto userDto); //error here
}
但之后呢 maven install
我有个问题:
Error: java: Role does not have an accessible parameterless constructor.
因为角色是enum,所以无法创建公共构造函数。我试过使用:
@Mapping(source = "roles", targer = "roles")
User fromDto(UserDto userDto);
和
@Mapping(source = "userDto.roles", targer = "user.roles")
User fromDto(UserDto userDto);
但没有效果。我该怎么修?
1条答案
按热度按时间mfpqipee1#
我采纳了@rup的建议,将我的角色类修改为: