- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是 mapstruct 的新手。我正在尝试映射 ItemInfo
至 Item
对象,以下是我的类。
public class ItemInfo {
private String itemOwner;
private String itemOwnerArea;
//getters and setters
}
以下是我打算转换为的类(class)
public class Item {
private UserInfo owner;
// getters and setters.
}
UserInfo 类(注意它有两个构造函数)
public class UserInfo {
private final String username;
private final String area;
public UserInfo(String username, String area){
//set
}
public UserInfo(String info) {
//set
}
// getters only
}
我已经创建了如下的映射器界面
@Mapper
public interface ItemMapper {
ItemMapper INSTANCE = Mappers.getMapper(ItemMapper.class);
@Mapping(source = "itemOwner", target = "owner.username")
@Mapping(source = "itemOwnerArea", target = "owner.area")
Item mapItemInfoToItem(ItemInfo itemInfo);
}
当我构建这个时,我收到以下错误
Ambiguous constructors found for creating com.app.test.UserInfo. Either declare parameterless
constructor or annotate the default constructor with an annotation named @Default.
你能指导我吗?
Property "username" has no write accessor in UserInfo for target name "owner.username".
谢谢
最佳答案
我们正在努力改进这个地方的错误信息。
从当前的错误信息
Ambiguous constructors found for creating
com.app.test.UserInfo
. Either declare parameterless constructor or annotate the default constructor with an annotation named@Default
.
@Default
注释并注释 MapStruct 应使用的默认构造函数。我强烈推荐这种方法。 Default
来自任何包的注释。
package foo.support.mapstruct;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target(ElementType.CONSTRUCTOR)
@Retention(RetentionPolicy.CLASS)
public @interface Default {
}
你已经这样做了,下一条错误消息:
Property "username" has no write accessor in UserInfo for target name "owner.username".
area
而不是关于
username
.该错误的另一个选择是您添加了一个空的无参数构造函数并且没有 setter 。
@Default
public UserInfo(String username, String area){
//set
}
关于java - "Ambiguous constructors found"使用 MapStruct 时有多个构造函数时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64657312/
为什么我的重载成员函数只是“不明确”为 char 而不是 int 和 string? 我试图通过重载的 equals() 函数汇集代码,为我的 Char 类创建一个单代码路径。当我使用 equals
我阅读了以下重要问题:Attributes in C#并学到了很多关于属性的知识。 我正在使用一个使用多个属性的库。示例: [State] public class USStates { [C
令我惊讶的是,以下代码在 VS2005 中编译时没有出现任何问题,因为在实现中对 Bar() 的调用让我停下来想知道如何消除歧义。 class Foo { public: void Bar(int
考虑以下几点: struct A { A(int, int) { } }; struct B { B(A ) { } // (1) expl
假设我们有这段代码,是从一个单独的问题中复制过来的: namespace x { void f() { } class C { void f()
考虑 C 代码 a = a = a。没有用于分配的序列点,因此此代码在编译时会产生有关 a 上未定义操作的警告。 a 在这里可能有哪些值? a 似乎无法更改值。这里实际上有未定义的行为还是编译器只是懒
题目地址:https://leetcode.com/problems/ambiguous-coordinates/description/ 题目描述: Wehad some 2-dimension
这个问题在这里已经有了答案: ORA-00918: column ambiguously defined in SELECT * (4 个答案) 关闭 5 年前。 所以我这学期很难理解 SQL。我真
我对 git 还很陌生。目前我尝试按照本教程使用分支名称和版本覆盖我的应用程序的图标:http://www.merowing.info/2013/03/overlaying-application-v
我已经升级到Xcode 11和Swift 5,并且在通过框架提供方法扩展时遇到了一个问题。更具体地说,在一个结构如下的项目中: -> Main Project -> Framework created
我有这样的片段: template bool apply_impl(data_t * d) const { return this->Last::apply(*
以下数据库结构: 表 cms_pages 包含带有 id、名称、标题等的页面 表 cms_pagerows 包含具有 cms_page_id 和排名的行 (cms_page_id 上的唯一索引,排名)
我正在尝试使用以下代码创建一个客户列表以及他们购买的品牌。 brands 表包含品牌名称,customer_id 在 customers 表中。要链接它们,我必须通过 receipts 表(连接到 c
我收到错误 “Integrity constraint violation: 1052 Column 'restaurant_id' in where clause is ambiguous' in”
我有一个在页面中间有一个表格 View 的布局。我希望根据用户设备的屏幕尺寸任意调整表格 View 的大小。在 ascii 中: +-----------+ |some stuff | +------
我正在尝试创建一个可以帮助您计算商品销售税的应用程序。当然应用程序需要乘法但我一直遇到错误: "Type of expression is ambiguous without more context
我正在尝试使用以下类型别名来定义它来传递一个函数: typealias AuthFunction = (String, String, AuthDataResultCallback?) -> ()
我对继承有疑问。假设我有 4 节课:基类A,B类继承A,C类继承A,BC 类继承 B 和 C class A { public: void test() {
我正在尝试整理一些代码。 我有 16 个类,它们都有一些共同的功能,我用宏抽象了这些功能: #define COMMON4( CLASS, BASE, ASSIGN, CHECK ) \ ex
在接下来的代码中,在 _tmain(..) 中调用 D::f 时出现不明确的错误因为 B::f 覆盖了 A::f,所以 A::vtable 中指向 f 的指针指向 B::f。 1) 为什么编译器会给出
我是一名优秀的程序员,十分优秀!