Mapstruct 不分配任何值
我使用 lombok、mapstruct 和 spring boot 2.6。我的IDE是intellij 2020.2
我的映射器
@Mapper(componentModel = "spring")
public interface UserMapper {
User userInfoToUser(UserInfo userInfo);
}
@Data
@NoArgsConstructor
@AllArgsConstructor
@Entity
public class User {
@Id
@GeneratedValue(generator="user_id_seq")
@SequenceGenerator(name="user_id_seq",sequenceName="user_id_seq", allocationSize=1)
Long id;
@Email
@Column(length = 254, unique = true)
String username;
@Column(length = 20)
String password;
@Enumerated(EnumType.STRING)
RoleEnum role;
@Column(columnDefinition = "int default 0")
int failedAttempt;
@Column(columnDefinition = "boolean default true")
boolean accountNonLocked;
@Column(columnDefinition = "boolean default false")
boolean requirePasswordChange;
@Column(columnDefinition = "boolean default true")
boolean enabled;
}
@Data
@NoArgsConstructor
@AllArgsConstructor
public class UserInfo {
private Long id;
@Email
@NotNull
@NotEmpty
private String username;
@Size(min = 8)
private String password;
}
生成的代码是
@Component
public class UserMapperImpl implements UserMapper {
@Override
public User userInfoToUser(UserInfo userInfo) {
if ( userInfo == null ) {
return null;
}
User user = new User();
return user;
}
}
在我的gradle文件中我
implementation 'org.mapstruct:mapstruct:1.4.2.Final'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
annotationProcessor 'org.mapstruct:mapstruct-processor:1.4.2.Final'
annotationProcessor 'org.projectlombok:lombok'
生成的代码不好,所有设置都丢失了。
与netbeans同样的问题
I use lombok, mapstruct and spring boot 2.6. My ide is intellij 2020.2
My mapper
@Mapper(componentModel = "spring")
public interface UserMapper {
User userInfoToUser(UserInfo userInfo);
}
@Data
@NoArgsConstructor
@AllArgsConstructor
@Entity
public class User {
@Id
@GeneratedValue(generator="user_id_seq")
@SequenceGenerator(name="user_id_seq",sequenceName="user_id_seq", allocationSize=1)
Long id;
@Email
@Column(length = 254, unique = true)
String username;
@Column(length = 20)
String password;
@Enumerated(EnumType.STRING)
RoleEnum role;
@Column(columnDefinition = "int default 0")
int failedAttempt;
@Column(columnDefinition = "boolean default true")
boolean accountNonLocked;
@Column(columnDefinition = "boolean default false")
boolean requirePasswordChange;
@Column(columnDefinition = "boolean default true")
boolean enabled;
}
@Data
@NoArgsConstructor
@AllArgsConstructor
public class UserInfo {
private Long id;
@Email
@NotNull
@NotEmpty
private String username;
@Size(min = 8)
private String password;
}
Code generated is
@Component
public class UserMapperImpl implements UserMapper {
@Override
public User userInfoToUser(UserInfo userInfo) {
if ( userInfo == null ) {
return null;
}
User user = new User();
return user;
}
}
In my gradle file I have
implementation 'org.mapstruct:mapstruct:1.4.2.Final'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
annotationProcessor 'org.mapstruct:mapstruct-processor:1.4.2.Final'
annotationProcessor 'org.projectlombok:lombok'
Code generated is not good, all set are missing.
same issue with netbeans
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

如果您使用 Lombok 1.18.16 或更高版本,则需要添加 lombok-mapstruct-binding 以使 Lombok 和 MapStruct 协同工作
if you are using Lombok 1.18.16 or newer you need to add lombok-mapstruct-binding in order to make Lombok and MapStruct work together