@EqualsAndHashCode(callSuper = false) @Accessors(chain = true)
时间: 2024-05-24 15:07:37 浏览: 15
@EqualsAndHashCode(callSuper = false)是Lombok注解中的一种,它用于生成equals()和hashCode()方法,可以通过设置callSuper参数为false来表示不调用父类的equals()和hashCode()方法,只调用本类中的属性进行比较。这个注解通常用于子类中,如果没有设置callSuper参数或者设置为true,则会同时调用父类和本类中的属性进行比较。
@Accessors(chain = true)也是Lombok注解中的一种,它可以用于链式编程,即在一个对象上直接调用多个方法,每个方法返回当前对象本身。使用这个注解可以省去手写setter方法的步骤,提高了代码的可读性和简洁性。
相关问题
@Data @EqualsAndHashCode(callSuper = false) @Accessors(chain = true) @TableName("country")
这段代码是使用了Lombok和MyBatis-Plus的注解,作用如下:
- `@Data`:自动生成Getter、Setter、`toString()`、`equals()`和`hashCode()`方法。
- `@EqualsAndHashCode(callSuper = false)`:自动生成`equals()`和`hashCode()`方法,`callSuper`属性设置为`false`表示不考虑父类的属性。
- `@Accessors(chain = true)`:生成链式调用的Setter方法,即每个Setter方法返回当前对象,可以连续调用多个Setter方法。
- `@TableName("country")`:将Java类映射到数据库中的表名为`country`,在使用MyBatis-Plus时需要用到。
这些注解可以简化Java代码的编写,提高开发效率。
@Data public class StorageLocationVo extends StorageLocation { @ApiModelProperty(value = "货架名") private String shelfName; private String type; private Integer sectionNum; private Integer layerNum; } @Data @EqualsAndHashCode(callSuper = false) @Accessors(chain = true) @TableName("t_storage_location") @ApiModel(value="StorageLocation对象", description="储位表") public class StorageLocation implements Serializable { private static final long serialVersionUID = 1L; @ApiModelProperty(value = "ID") @TableId(value = "id", type = IdType.AUTO) private Long id; @ApiModelProperty(value = "储位名称") private String name; @ApiModelProperty(value = "储位编码") private String code; @ApiModelProperty(value = "库房id") private Long storeroomId; @ApiModelProperty(value = "站点id") private Long siteId; @ApiModelProperty(value = "识别编码") private String identifyCode; @ApiModelProperty(value = "货架id") private Long shelfId; @ApiModelProperty(value = "是否删除 0:正常 1:删除") @TableLogic private String isDelete; @ApiModelProperty(value = "创建时间") @TableField(fill = FieldFill.INSERT) private Date createTime; @ApiModelProperty(value = "更新时间") @TableField(fill = FieldFill.UPDATE) private Date updateTime; @ApiModelProperty(value = "所属站点名称") @TableField(exist = false) private String siteName; @ApiModelProperty(value = "所属库房名称") @TableField(exist = false) private String storeroomName; @ApiModelProperty(value = "所属货架名称") @TableField(exist = false) private String shelfName; @ApiModelProperty(value = "所属货架编码类型") @TableField(exist = false) private String codeRule; @ApiModelProperty(value = "所属货架节数") @TableField(exist = false) private Integer sectionNum; @ApiModelProperty(value = "所属货架层数") @TableField(exist = false) private Integer layerNum; } 分析一下为什么报java: com.tuimi.gwznkf.storage.entity.vo.StorageLocationVo中的setShelfName(java.lang.String)无法覆盖com.tuimi.gwznkf.storage.entity.StorageLocation中的setShelfName(java.lang.String) 返回类型void与com.tuimi.gwznkf.storage.entity.StorageLocation不兼容 问题解决
这个问题是由于在子类StorageLocationVo中定义了一个与父类StorageLocation中同名的属性shelfName,并且使用了@Data注解,自动生成了一个setShelfName方法,但是返回类型不同导致的。
解决该问题有两种方法:
1. 删除子类StorageLocationVo中的属性shelfName,因为父类中已经定义了该属性,所以不需要在子类中再定义一次。
2. 在子类StorageLocationVo中重新定义setShelfName方法,并且保证方法签名(包括返回类型、方法名和参数列表)与父类中的方法一致。可以使用@Override注解来表示该方法是对父类方法的重写。例如:
```
@Override
public void setShelfName(String shelfName) {
super.setShelfName(shelfName);
// 子类自定义的操作
}
```
需要注意的是,在子类中重写父类方法时,应该先调用父类的方法,再进行子类自己的操作,以保证方法的正确性。
相关推荐
![jar](https://img-home.csdnimg.cn/images/20210720083455.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![bat](https://img-home.csdnimg.cn/images/20210720083646.png)