This is my code,it can get the response with 200 but the database doesn't update.The backend told that it had received null.
axios.post('api/nosql/LineController/insertLine', {
line:{
id:this.id,
directional:this.directional,
kilometer:this.slide1.distance,
runtime:runtime,
interval:this.slide2.shift,
type:this.type,
},
stationList: this.newPlatforms,
})
And I also tried this code, the problem remained.
axios({
method:"post",
changeOrigin:"true",
url:"api/nosql/LineController/insertLine",
transformRequest:[
function(data){
return QS.stringify(data);
}
],
data: {
line:{
id:this.id,
directional:this.directional,
kilometer:this.slide1.distance,
runtime:runtime,
interval:this.slide2.shift,
type:this.type,
},
stationList: this.newPlatforms,
}
})
the code at backend
public Object insertLine(HttpServletRequest request) throws IOException {
StringBuffer lineInfoAndStations = new StringBuffer();
String line;
BufferedReader reader;
reader = request.getReader();
while(null != (line = reader.readLine())) {
lineInfoAndStations.append(line);
}
return service.addLine(lineInfoAndStations.toString());
}
if you use content-type as application/json please remove transformRequest attribute. if you use application/x-www-form-urlencoded ,it can not post array or object to backend