报错UserInfo()' in 'com.example.gmall.cart.pojo.UserInfo' cannot be applied to '(l


新建pojo类

@Data
public
class UserInfo { private Long userId; private String userKey; }

使用Lombook中的data注解,但是在使用时报错

UserInfo()' in 'com.example.gmall.cart.pojo.UserInfo' cannot be applied to '(long, java.lang.String)'

原因:pojo类只是用了Data注解,缺少了构造方法,

解决:使用注解@AllArgsConstructor  @NoArgsConstructor 或者直接进行构造

@Data
@AllArgsConstructor
@NoArgsConstructor
public class UserInfo {
    private Long userId;
    private String userKey;
}

相关