我想从表名广告更新atributte ad_stat但我收到错误:
500 Could not parse multipart servlet request; nested exception is javax.servlet.ServletException:org.apache.tomcat.util.http.fileupload.FileUploadBase$InvalidContentTypeException: the request doesn't contain a multipart/form-data or multipart/mixed stream, content type header is null"
这是更新数据的代码
@ApiOperation(value = "deactiveAd", nickname = "deactive Ad")
@RequestMapping(method = RequestMethod.GET, path = "ads/deactive", produces
= "application/json")
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Success"),
@ApiResponse(code = 401, message = "Unauthorized"),
@ApiResponse(code = 403, message = "Forbidden"),
@ApiResponse(code = 404, message = "Not Found"),
@ApiResponse(code = 500, message = "Failure")
})
public Response deactiveAd(@RequestPart(name = "adsId", required = true)
int ad_id){
Response response = new Response();
DbHandler db = new DbHandler();
if(db.getResult() == 0){
try{
String sql = "UPDATE advert SET ad_stat = false
WHERE ad_id = "+ad_id+";";
if(!db.execute(sql)) {
response.setStatus("0");
}else{
response.setStatus("3");
}
db.closeStatement();
db.closeConnection();
}catch(SQLException e) {
response.setStatus("1");
try{
db.closeConnection();
db.closeStatement();
}catch(SQLException e1) {
}
}
}else{
response.setStatus(String.valueOf(db.getResult()));
}
return response;
}
ad_stat的数据类型是boolean,我试图将其伪造
答案 0 :(得分:0)
更改
@RequestMapping(method = RequestMethod.GET, path = "ads/deactive", produces = "application/json")
到
@RequestMapping(method = RequestMethod.POST, path = "ads/deactive", produces = "application/json",Content-Type="multipart/formdata")
答案 1 :(得分:0)
在表单中添加enctype。
<form enctype=”multipart/form-data”></form>