Spring MVC - REST Api, keep getting 400 Bad Request when trying to POST -


i have rest api service should receive post calls.

i'm using postman test them, keep getting 400 bad request error, no body, maybe i'm building bad controller...

this controller

@postmapping("/object/delete")     public responseentity<?> deleteobject(@requestbody long objectid) {         logger.debug("controller hit");         object o = service.findbyobjectid(objectid);         if(o!=null){          service.deleteobject(object);          return new responseentity<>(httpstatus.ok);                    }          return new responseentity<>(httpstatus.not_found);      } 

using @requestbody should send request in json, in way:

{ "objectid":100 } 

but 400 error, , strange think logger logger.debug("controller hit"); it's not printed in logs...

sending { "objectid":100 } result in receiving object x objectid attribute in java method.

if need send id, can use @pathvariable

@postmapping("/object/{id}/delete") public responseentity<?> deleteobject(@pathvariable("id") long objectid) { 

also, consider using deletemapping instead of postmapping delete object.


Comments

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -