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

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -