When using mybatisplus to query sql, an Error attempting to get column 'ID' from result set error is reported.

Problem description:
When using the following code to query, an Error attempting to get column 'ID' from result set error is reported:

 LambdaQueryWrapper<TimeFeature> wrapper = new LambdaQueryWrapper<>();
 wrapper.eq(TimeFeature::getDate, currentDateTime);
 TimeFeature timeFeature = timeFeatureMapper.selectOne(wrapper);

First eliminate the case problem of database fields.
Then considering that the ID field is not very important in this round of logic, the following changes were made to the code and the query field was specified:

LambdaQueryWrapper<TimeFeature> wrapper = new LambdaQueryWrapper<>();
wrapper.select(TimeFeature::getDate,TimeFeature::getDayType5)
.eq(TimeFeature::getDate, currentDateTime);
TimeFeature timeFeature = timeFeatureMapper.selectOne(wrapper);

The result query is normal, and then it can be concluded that there is a problem in the mapping process of the result set to the entity class.
Then by checking the code, I found that my entity class uses @AllArgsConstructorannotations.

@Data
@TableName("TIME_FEATURE")
@ApiModel(value = "TimeFeature对象", description = "日期类型映射")
@AllArgsConstructor
public class TimeFeature extends BaseEntity{
    
    

    @ApiModelProperty("日期")
    private LocalDateTime date;

    @ApiModelProperty("类型")
    private Integer dayType5;

}

This annotation causes the specified default constructor to be a method containing only two parameters: date and dayType5. Therefore, the corresponding result set cannot be mapped to the entity class through the default construction method.
So removing this annotation solves the problem.
Extended thinking, will using @Builderannotations cause similar problems?

Guess you like

Origin blog.csdn.net/qq_42740899/article/details/132673549