Adding links to every record with Spring REST + MongoDB -
i'm trying add links every record in databse, trying implement hateoas concept. however, have been experiencing trouble this. tried following guide https://spring.io/guides/gs/rest-hateoas/. no success. how , should write code adding links? because doesn't seem work when try write in controller method because withselfrel() undefined.
basically i'm trying add link every account made in database.
//create account @requestmapping(value="/accounts", method = requestmethod.post) public responseentity<?> accountinsert(@requestbody account account) { account = new account(account.getfirstname(), account.getlastname(), account.getemail(), account.getpassword(), account.getbirthdate(), account.getactivities(), account.getfriends()); accountrepository.save(account); //account.add(linkto(methodon(accountcontroller.class, accountinsert(account)).withselfrel())); /// here try httpheaders httpheaders = new httpheaders(); httpheaders.setlocation(servleturicomponentsbuilder.fromcurrentrequest().build().touri()); return new responseentity<>(null, httpheaders, httpstatus.created); }
thank in advance!
you can not use method inside same one
try :-
link self=linkto(accountcontroller.class).slash(account.getid()).withselfrel();
or can refer given link
Comments
Post a Comment