前后端分离 参数对应转化时出现Java的反序列化异常,我所遇到的坑
vue-springboot 前后端分离 参数对应转化时出现Java的反序列化异常,我所遇到的坑
不废话 亮代码
vue定义的用来装数据的容器ruleForm
// An highlighted block
ruleForm: {
c_name: "",
c_card_id: "",
c_group_id: "",
c_group_name: "",
c_station: "",
c_qualification: "",
c_worktype_id: "",
c_worktype_name: "",
c_mobile: "",
c_photo: [],
// c_certificate_path: "",
c_base64: ""
},
上传标签(doUpload)
// An highlighted block
<el-upload
:file-list="fileList"
ref="upload"
style="position:absolute"
:limit="1"
:auto-upload="false"
accept=".jpg, .jpeg, .png, .gif, .bmp, .pdf, .JPG, .JPEG, .PBG, .GIF, .BMP, .PDF"
:multiple="false"
:with-credentials="true"
:action="url"
list-type="picture-card"
:on-success="handleSuccess"
:on-change="handleChange"
:on-error="handleError"
:on-remove="handleRemove"
>
<i class="el-icon-plus">照片</i>
</el-upload>
触发事件( this.ruleForm.c_photo = res.data;)拿取图片把名字给c_photo=[]
// An highlighted block
//选择图片成功执行的方法
handleSuccess(res, file, fileList) {
// alert(res)
this.isSubmit = true;
if (res.code == 200) {
//看这里--------------//看这里----------------//看这里-----------//看这里
this.ruleForm.c_photo = res.data;
console.log(res.data);
api.addSomeThingInsertTable(this.ruleForm).then(response => {
if (response.code == 200) {
this.$notify.success(response.data);
location.reload();
} else {
this.$notify.error(response.msg);
}
});
}
console.log(this.isSubmit);
},
//选取失败执行
handleError(error, file, fileList) {
this.isSubmit = true;
this.$notify.error(response.msg);
},
//删除时执行
handleRemove(file, fileList) {},
//选取图片时触发(fileList 装则是el-upload 里面装的所有文件)
handleChange(file, fileList) {
this.fileList = fileList;
},
Java实体类
public class Entity {
private Integer c_id;
/**
* id card
*/
private String c_card_id;
/**
* username
*/
private String c_name;
/**
* 单位id
*/
private Integer c_group_id;
/**
* 单位名称
*/
private String c_group_name;
/**
* 岗位
*/
private String c_station;
/**
* 工种id
*/
private String c_worktype_id;
/**
* 工种name
*/
private String c_worktype_name;
/**
* 工种name
*/
private String c_qualification;
/**
* 联系方式
*/
private String c_mobile;
/**
* 照片
*/
private String c_photo;
/**
* 照片base64
*/
private String c_base64;
private Integer user_id;
public Integer getUser_id() {
return user_id;
}
public void setUser_id(Integer user_id) {
this.user_id = user_id;
}
public String getC_photo() {
return c_photo;
}
public void setC_photo(String c_photo) {
this.c_photo = c_photo;
}
public String getC_base64() {
return c_base64;
}
public void setC_base64(String c_base64) {
this.c_base64 = c_base64;
}
public Integer getC_id() {
return c_id;
}
public void setC_id(Integer c_id) {
this.c_id = c_id;
}
public String getC_card_id() {
return c_card_id;
}
public void setC_card_id(String c_card_id) {
this.c_card_id = c_card_id;
}
public String getC_name() {
return c_name;
}
public void setC_name(String c_name) {
this.c_name = c_name;
}
public Integer getC_group_id() {
return c_group_id;
}
public void setC_group_id(Integer c_group_id) {
this.c_group_id = c_group_id;
}
public String getC_group_name() {
return c_group_name;
}
public void setC_group_name(String c_group_name) {
this.c_group_name = c_group_name;
}
public String getC_station() {
return c_station;
}
public void setC_station(String c_station) {
this.c_station = c_station;
}
public String getC_mobile() {
return c_mobile;
}
public void setC_mobile(String c_mobile) {
this.c_mobile = c_mobile;
}
public String getC_worktype_id() {
return c_worktype_id;
}
public void setC_worktype_id(String c_worktype_id) {
this.c_worktype_id = c_worktype_id;
}
public String getC_worktype_name() {
return c_worktype_name;
}
public void setC_worktype_name(String c_worktype_name) {
this.c_worktype_name = c_worktype_name;
}
public String getC_qualification() {
return c_qualification;
}
public void setC_qualification(String c_qualification) {
this.c_qualification = c_qualification;
}
@Override
public String toString() {
return "SourceUser{" +
"c_id=" + c_id +
", c_card_id='" + c_card_id + '\'' +
", c_name='" + c_name + '\'' +
", c_group_id=" + c_group_id +
", c_group_name='" + c_group_name + '\'' +
", c_station='" + c_station + '\'' +
", c_worktype_id='" + c_worktype_id + '\'' +
", c_worktype_name='" + c_worktype_name + '\'' +
", c_qualification='" + c_qualification + '\'' +
", c_mobile='" + c_mobile + '\'' +
", c_photo='" + c_photo + '\'' +
", c_base64='" + c_base64 + '\'' +
", user_id=" + user_id +
'}';
}
}
###指向后端(马上就要出问题了)
// An highlighted block
mounted() {
this.uploadData = {
meet_id: this.meet_id
};
this.doUpload =
G.BASE_URL +
"/zf/uploadFileWithForm?access_token=" +
sessionStorage.getItem("token");
},
此时在表单中新增各种数据 不提交上传图片 连debugger都没进 就
Java控制台报错
// An highlighted block
annot deserialize instance of `java.lang.String` out of START_ARRAY token
(through reference chain: com.demo1.demo11.entity.Entity ["c_photo"])]
## 找了半天原来是 参数c_photo=[] 在接收时不能被String接收,与其定义 c_photo: [],还不如不定义,修改后的容器
// An highlighted block
ruleForm: {
},