- REST API 활용하여 CUD 처리
1. INSERT : cityAdd
@PostMapping(value="cityAdd")
public ResponseEntity<City> cityAdd(@RequestBody City city) {
try {
log.info("city = {}", city.toString());
return new ResponseEntity<>(infoService.insert(city), HttpStatus.OK);
} catch (Exception e) {
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
2. UPDATE : cityEdit
@PostMapping(value="cityEdit")
public ResponseEntity<String> cityEdit(@RequestBody City city) {
try {
log.info("city = {}", city.toString());
Integer updatedCnt = infoService.updateById(city);
return new ResponseEntity<>(String.format("%d updated", updatedCnt), HttpStatus.OK);
}catch (Exception e) {
log.error(e.toString());
return new ResponseEntity<>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
}
}
3. DELETE : cityDelete
@PostMapping(value="cityDelete")
public ResponseEntity<String> cityDelete(@RequestBody City city) {
try {
log.info("city id = {}", city.getId());
Integer deletedCnt = infoService.deleteById(city.getId());
return new ResponseEntity<>(String.format("%d deleted", deletedCnt), HttpStatus.OK);
}catch (Exception e) {
log.error(e.toString());
return new ResponseEntity<>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
}
}