I send a request to the rest-api to store a object into mysql database.
Which step is missing that i can store via Jpa the objects into my database?
Here is the Rest-Controller
@RestController
public class OwnerRestController {
@Autowired
private final OwnerRestRepository repo;
public OwnerRestController(OwnerRestRepository repo) {this.repo = repo;}
@RequestMapping(value="/owner/add", method=RequestMethod.POST)
public Owner create(@RequestBody Map<String, String> body){
Owner o = new Owner();
o.setFirstName(body.get("firstName"));
o.setLastName(body.get("lastName"));
o.setAddress(body.get("address"));
o.setCity(body.get("city"));
o.setTelephone(body.get("telephone"));
this.repo.save(o);
return o;
}
}
Here is the Repository Interface
public interface OwnerRestRepository extends CrudRepository<Owner,integer>{}
Here is the JSON-Object Owner
{
"firstName":"fname",
"lastName":"lname",
"address":"address1",
"city":"city1",
"telephone":"4711"
}
Server Response
{
"id": 11,
"firstName": "fname",
"lastName": "lname",
"address": "address1",
"city": "city1",
"telephone": "4711"
}
What's wrong in the code that the data can't be stored in the database?
Best regards, Mux