查询sql,报错信息如下:
com.mysql.cj.exceptions.NumberOutOfRange
Error attempting to get column 'store_id' from result set.
Cause: java.sql.SQLDataException: Value '2724383930083155999' is outside of valid range for type java.lang.Integer
实体类:
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("t_store_withdrawal_setting")
public class StoreWithdrawalSetting implements Serializable {
private static final long serialVersionUID = 1L;
@TableId(value = "id", type = IdType.AUTO)
private Long id;
@ApiModelProperty(value = "商家ID")
private Long storeId;
@ApiModelProperty(value = "修改次数")
private Integer frequency;
@ApiModelProperty(value = "修改月份")
private String createTime;
public StoreWithdrawalSetting(Long storeId, Integer frequency, String createTime) {
this.createTime = createTime;
this.frequency = frequency;
this.storeId = storeId;
}
}
mapper层:
@Mapper
public interface StoreWithdrawalSettingMapper extends BaseMapper<StoreWithdrawalSetting> {
/**
* 查询商家当月修改提现规则的次数
* @param storeId
* @return
*/
StoreWithdrawalSetting selectStoreWithdrawal(Long storeId);
}
xml:
<select id="selectStoreWithdrawal" resultType="com.mallplus.mealordering.model.entity.StoreWithdrawalSetting">
SELECT * FROM t_store_withdrawal_setting WHERE store_id= #{storeId} AND create_time = DATE_FORMAT(NOW(),'%Y-%m-%e');
</select>
如上信息,查询的时候会一直报错,这里原因有以下几点:
1、查看下 t_store_withdrawal_setting 的 store_id 字段是不是 bigint 类型
2、接收的实体类对应的属性是不是 Long
3、实体类如果不写构造,默认是有无惨构造的。如果自己写了构造(非无参),此时需要加上一个无参构造
(通俗的解释,如有错误,请大佬纠正:对象实例化的时候,如果写了构造方法,就会使用已经编写的。如果多个构造方法,使用加@Autowired注解的。如上代码,实体类中写了一个三参数的无参构造,所以查询sql的时候报错,此时需要添加一个无参构造)
可以使用注解(个人建议,dto、vo等对象都添加下面的注解) :
@NoArgsConstructor // 无参
@AllArgsConstructor // 全参
@Data
@EqualsAndHashCode(callSuper = false)
@NoArgsConstructor
@AllArgsConstructor
@TableName("t_store_withdrawal_setting")
@ApiModel(value = "StoreWithdrawalSetting对象", description = "商家当月修改提现方式次数记录表")
public class StoreWithdrawalSetting implements Serializable {
private static final long serialVersionUID = 1L;
@TableId(value = "id", type = IdType.AUTO)
private Long id;
@ApiModelProperty(value = "商家ID")
private Long storeId;
@ApiModelProperty(value = "修改次数")
private Integer frequency;
@ApiModelProperty(value = "修改月份")
private String createTime;
public StoreWithdrawalSetting(Long storeId, Integer frequency, String createTime) {
this.createTime = createTime;
this.frequency = frequency;
this.storeId = storeId;
}
}
此时查询sql,就可以成功查询。