mapstruct中String映射list,String To List

时间:2025-01-26 22:42:08

代码开发中po转vo中用到了mapstruct。

在进行某一个对象的转换中,启动服务,Build出错,代码并没有报错。

Error:(33, 17) java: Can't map property " handlSituation" to "<> handlSituation". 
Consider to declare/implement a mapping method: "<> map( value)".

第一次使用mapstruct,不是很熟悉,发现是po中的字段为String,vo中是List,所以报错转换异常。
最终解决方案如下:

@Mapper(imports = )
public interface MapStructMapper {
	MapStructMapper INSTANCE = ();
	
	    @Mapping(expression = "java((()))", target = "handVo")
    CMainVo cMainToCMainVo(CMain cMain);
}
public class MapStruct {
    public static List<String> strToList(String hand){
        List<String> list = new ArrayList<>();
        (hand);
        return list;
    }
}

哪有不足,欢迎指出!

参考:/questions/53132415/mapstruct-mapping-string-to-liststring
参考:/mmzs/p/