I am new to spring boot, creating a simple CRUD operations using Rest API. I have written two methods one for GET and POST. Get works fine but when I try to access post method it's not working its shows 404 error.
@RequestMapping(value = "/create", method = RequestMethod.POST)
public ResponseEntity<?> addStudent(@RequestBody Employee employee){
service.saveOrUpdate(employee);
return new ResponseEntity<Object>("added succcessfully", HttpStatus.OK);
}
this returns:
{
"status": 404,
"error": "Not Found",
"message": "No message available",
"path": "/api/create"
}
@RestController
@EnableAutoConfiguration
@RequestMapping(value = "/api")
public class EmployeeController{
@Autowired
EmployeeService service;
@RequestMapping(value = "/create", method = RequestMethod.POST)
public ResponseEntity<?> createEmployee(@RequestBody Employee employee){
service.saveOrUpdate(employee);
return ResponseEntity.ok().body("Added");
}
@RequestMapping(value = "/list", method = RequestMethod.GET)
public ResponseEntity<?> list(){
List<Employee> employee = service.getAllEmployee();
return new ResponseEntity<List<Employee>>(employee, HttpStatus.OK);
}