是的,报错提示的意思是在rsp2AcTokenDTO方法中没有名为signupType的源参数。根据你的代码,signupType应该是EnableUserResp对象中的一个属性,而不是方法的参数。

要解决这个问题,你可以将signupType作为EnableUserResp对象中的一个属性,并在@Mapping注解中使用source指定该属性的值。修改后的代码如下:

@Mapper(
        config = BaseConverterMapper.class,
        injectionStrategy = InjectionStrategy.CONSTRUCTOR,
        imports = {JwtUtil.class}
)
public interface Converter2AcTokenDTO {

    @Mappings({
            @Mapping(target = "tokenType", source = "tokenType"),
            @Mapping(target = "signupType", source = "signupType", qualifiedByName = "mapSignupType"),
            @Mapping(target = "vip", source = "vip", qualifiedByName = "mapVip"),
            @Mapping(target = "expiresTime", qualifiedByName = "mapExpiresTime"),
    })
    AcTokenDTO rsp2AcTokenDTO(EnableUserResp resp, TokenType tokenType);

    @Named("mapSignupType")
    default SignupType mapSignupType(EnableUserResp resp) {
        return SignupType.fromValue(resp.getSignupType());
    }

    @Named("mapVip")
    default VIP mapVip(EnableUserResp resp) {
        return VIP.fromValue(resp.getVip());
    }

    @Named("mapExpiresTime")
    default LocalDateTime mapExpiresTime() {
        return JwtUtil.getTokenExpiresTime();
    }

}

这样修改后,rsp2AcTokenDTO方法只接受一个EnableUserResp对象和一个TokenType对象作为参数。signupType和其他属性的值将从EnableUserResp对象中获取,并通过相应的转换方法进行转换

使用springboot开发使用mapstruct进行bean之间的转换下面是我写的代码:import comcryptoquiltapiuserresponseEnableUserResp;import comcryptoquiltauthdtoAcTokenDTO;import comcryptoquiltcommoncoremodelBaseConverterMapper;import co

原文地址: http://www.cveoy.top/t/topic/igeW 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录