There are two set of data: provinces and cities.
The controller for provinces works properly. After posting with this method:
@RequestMapping(method=RequestMethod.POST, value="/provinces")
public void addProvince(@RequestBody Province province) {
provinceService.addProvince(province);
}
and get it with this method:
@RequestMapping("/provinces")
public List<Province> getAllProvinces( ) {
return provinceService.getAllProvinces();
}
the object I posted shows on my browser.
{
"id": "ks",
"name": "Kangso",
"description": "Peace River and So City"
}
However, after posting a city to that province:
@RequestMapping(method=RequestMethod.POST,
value="/provinces/{provinceId}/cites/")
public void addCity(@RequestBody City city,
@PathVariable String provinceId) {
city.setProvince(new Province(provinceId, "", ""));
cityService.addCity(city);
}
with the method in CityService:
public void addCity(City city) {
cityRepository.save(city);
}
and read it with the method:
@RequestMapping("/provinces/{provinceId}/cities")
public List<City> getAllCities(@PathVariable String provinceId) {
return cityService.getAllCities(provinceId);
}
and this request:
The posted object was not showing.
No error came out while compiling or sending the requests, and the RequestMapping for cities worked like other requests:
Mapped "{[/provinces/{provinceId}/cites/],methods=[POST]}"
Mapped "{[/provinces/{provinceId}/cities]}"
Mapped "{[/provinces]}"
Mapped "{[/provinces],methods=[POST]}"
I'm not sure whether the city is properly posted, and now I'm also trying to check what was actually posted in the CityService with eclipse STS.