报错
JSON parse error: Cannot construct instance of com.example.entity.Business
(although at least one Creator exists): no int/Int-argument constructor/factory method to deserialize from Number value (22)
这个错误是由于在将JSON数据解析为Java对象时,无法找到一个合适的构造函数或工厂方法来处理从Number值(22)开始的解析。要解决这个问题,您需要检查您的Business实体类,确保它有一个合适的构造函数或工厂方法来处理从Number值开始的解析。
后端接口
@DeleteMapping("/deleteBatch")
public Result deleteBatch(@RequestBody List<Business> ids) {
businessService.deleteBatch(ids);
return Result.success();
}
前端调用
this.$request.delete('/business/deleteBatch', {data: this.ids})...
实体类
public class Business {
/**
* 主键
*/
private Integer id;
/**
* 用户名
*/
private String username;
/**
* 密码
*/
private String password;
/**
* 名称
*/
private String name;
/**
* logo
*/
private String avatar;
/**
* 角色
*/
private String role;
/**
* 电话
*/
private String phone;
/**
* 简介
*/
private String info;
/**
* 地址
*/
private String address;
/**
* 营业证书
*/
private String license;
/**
* 审核状态
*/
private String status;
/**
* 营业时间
*/
private String timeRange;
/**
* 类型
*/
private String type;
public Business(Integer id, String username, String password, String name, String avatar, String role, String phone, String info, String address, String license, String status, String timeRange, String type) {
this.id = id;
this.username = username;
this.password = password;
this.name = name;
this.avatar = avatar;
this.role = role;
this.phone = phone;
this.info = info;
this.address = address;
this.license = license;
this.status = status;
this.timeRange = timeRange;
this.type = type;
}
public Business(Integer id) {
this.id = id;
}
public Business() {
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAvatar() {
return avatar;
}
public void setAvatar(String avatar) {
this.avatar = avatar;
}
public String getRole() {
return role;
}
public void setRole(String role) {
this.role = role;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getInfo() {
return info;
}
public void setInfo(String info) {
this.info = info;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getLicense() {
return license;
}
public void setLicense(String license) {
this.license = license;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public String getTimeRange() {
return timeRange;
}
public void setTimeRange(String timeRange) {
this.timeRange = timeRange;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
}
解决方法
在对应的实体类中单独创建一个只有id的构造器
public Business(Integer id) {
this.id = id;
}