@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不兼容 问题解决
时间: 2024-01-21 07:02:07 浏览: 27
这个问题是由于在子类StorageLocationVo中定义了一个与父类StorageLocation中同名的属性shelfName,并且使用了@Data注解,自动生成了一个setShelfName方法,但是返回类型不同导致的。
解决该问题有两种方法:
1. 删除子类StorageLocationVo中的属性shelfName,因为父类中已经定义了该属性,所以不需要在子类中再定义一次。
2. 在子类StorageLocationVo中重新定义setShelfName方法,并且保证方法签名(包括返回类型、方法名和参数列表)与父类中的方法一致。可以使用@Override注解来表示该方法是对父类方法的重写。例如:
```
@Override
public void setShelfName(String shelfName) {
super.setShelfName(shelfName);
// 子类自定义的操作
}
```
需要注意的是,在子类中重写父类方法时,应该先调用父类的方法,再进行子类自己的操作,以保证方法的正确性。
相关问题
这是vo类 @Data @ApiModel(value = "飞行任务管理-后端列表页vo") public class BisTaskVO extends PageReqVO { @ApiModelProperty(value = "逻辑删除 1是 0否") private Integer isDel; } 帮我用mybatis-plus写个逻辑删除
好的,你可以按照以下步骤使用Mybatis-Plus实现逻辑删除:
1. 在实体类中添加逻辑删除字段
```java
@Data
@ApiModel(value = "飞行任务管理-后端列表页vo")
public class BisTaskVO extends PageReqVO {
@ApiModelProperty(value = "逻辑删除 1是 0否")
@TableLogic // 添加逻辑删除注解
private Integer isDel;
}
```
2. 配置Mybatis-Plus逻辑删除插件
```java
@Configuration
@MapperScan("com.example.mapper")
public class MybatisPlusConfig {
// 配置逻辑删除插件
@Bean
public ISqlInjector sqlInjector() {
return new LogicSqlInjector();
}
// 配置分页插件
@Bean
public PaginationInterceptor paginationInterceptor() {
return new PaginationInterceptor();
}
}
```
3. 执行逻辑删除操作
```java
@Service
public class BisTaskService {
@Autowired
private BisTaskMapper bisTaskMapper;
public boolean deleteById(Long id) {
int rows = bisTaskMapper.deleteById(id);
return rows > 0;
}
}
```
当执行删除操作时,Mybatis-Plus会自动将逻辑删除字段设置为1,而不是真正从数据库中删除该记录。如果需要查询已删除的记录,可以使用Mybatis-Plus提供的恢复逻辑删除的方法。
@Data @ApiModel(value = "项目管理") public class BisProjectVO { @ApiModelProperty(value = "id") private Integer id; @ApiModelProperty(value = "项目名称") private String projectName; } 根据id查询项目名称,用mybatis-plus写,不要写mapper和sql
可以使用 Mybatis-Plus 提供的便捷方法 `selectById`,代码如下:
```
@Service
public class BisProjectService extends ServiceImpl<BisProjectMapper, BisProjectVO> {
public String getProjectNameById(Integer id){
BisProjectVO bisProjectVO = this.baseMapper.selectById(id);
return bisProjectVO == null ? null : bisProjectVO.getProjectName();
}
}
```
其中,`BisProjectMapper` 是继承了 Mybatis-Plus 的 `BaseMapper` 的自定义 Mapper 接口。`this.baseMapper.selectById(id)` 就是使用 Mybatis-Plus 提供的 `selectById` 方法查询 id 对应的项目记录,并将结果封装成 `BisProjectVO` 对象返回。最后,返回 `BisProjectVO` 对象中的项目名称属性即可。