Hello I want to send a string from my Angular 4 post request to my java spring mvc controller and return it's value.
in angular 4 function:
let body = 'example'
http
.post('favourite', body)
.subscribe(
data => {
console.log('favourite received');
},
error => {
console.log('an error occured');
}
)
in my java code:
@RequestMapping(value= "/favourite", method = RequestMethod.POST)
@ResponseBody
public void createFavourite(@RequestParam(value="body") String favourite){
Favourite.setFav(favourite);
}
Essentially I want to send just thestring: 'example' as the body and then receive it, again as a string in my java spring controller and set it for my Favourite fav value, so then if I have a Favourites.getFav()
function in Favourite it will return "example". What am I doing wrong with the requestsand how can I make it work?