Mapstruct 不分配任何值

发布于 01-17 06:52 字数 1845 浏览 1 评论 0原文

我使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

七月上2025-01-24 06:52:05

如果您使用 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文