mapstruct v1.3.1FINAL:静态方法的导入未生成

huangapple go评论79阅读模式
英文:

mapstruct v1.3.1FINAL: imports from static methods aren't generated

问题

我们正在使用MapStruct 1.3.1 FINAL(与lombok v1.18.4结合使用,如果有关系的话),生成的类无法编译,因为表达式映射中使用的静态方法的导入未生成。有任何线索吗?

生成的代码存在编译错误,因为缺少ValueUtil的导入:

request.setValue( ValueUtil.getValue(sourceValue) );
英文:

We are using mapstruct 1.3.1FINAL (in combination with lombok v1.18.4 if that matters) and the generated classes aren't compiling because the imports of the static methods used in expression mappings aren't generated. Any clues?

@Mapping(target = "value", expression = "java(ValueUtil.getValue(sourceValue))")

The generated code has compilation errors because the import of ValueUtil is missing :

request.setValue( ValueUtil.getValue(sourceValue) );

答案1

得分: 10

最终我明白了,尝试了Sjaak写的内容。

@Mapper(imports = { ValueUtil.class })

这个导入成功了。也会尝试一下Deepak的回答是否有效。

英文:

Finally i got it, tried out what Sjaak wrote.

@Mapper(imports = { ValueUtil.class })

The import made it. Will try out if Deepaks answer works as well.

答案2

得分: 4

请尝试使用完全限定的类名来引用 ValueUtil,即 packagename.ValueUtil。这将为 MapStruct 提供上下文以定位该类。

英文:

Please try with fully qualified class name for ValueUtil I.e. packagename.ValueUtil. This will provide the context to mapstruct to locate the class.

答案3

得分: 3

你可以向 @Mapper 注解添加一个导入语句,专门用于这种情况。查看文档

英文:

you can add an import statement to the @Mapper annotation, precisely for such cases. Checkout the documentation.

huangapple
  • 本文由 发表于 2020年9月9日 23:30:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/63814886.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定