I'm just trying to walk through DTO concept in spring boot app So I create a customer mode, Customer DTO, Customer Service and Controller
But when i test the API through postman, it's insert null values for all attrivbutes, but i don't now why...
and this is the service :
@Override
@Transactional
public Customer addCustomer(Customer customer) {
Customer newCustomer = cutomerRepository.save(customer);
return newCustomer;
}
and at last this is the controller :
public ResponseEntity<Customer> addCustomer(CustomerDTO customer) {
try {
System.out.println(customer.getEmail() "000000000000000000000000");
Customer newCustomer = customerService
.addCustomer(new Customer(customer.getSerialNumber(), customer.getFirstName(),customer.getLastName(),customer.getEmail(),customer.getMobileNumber()));
System.out.println(customer.getEmail() "************************");
return new ResponseEntity<>(newCustomer, HttpStatus.CREATED);
} catch (Exception e) {
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
the output from 000 and *** are null, and this is how i insert values
Any help or Idea ?
CodePudding user response:
You need @RequestBody
on controller's handler method arg
public ResponseEntity<Customer> addCustomer(@RequestBody CustomerDTO customer) {