DTO插入null值在Springboot中的数据库中
我只是想在Spring Boot应用程序中浏览DTO概念,因此我创建了客户模式,客户DTO,客户服务和控制器,
但是当我通过Postman测试API时,它是所有vertivbutes的插入null值,但我不知道现在为什么...
这是服务:
@Override
@Transactional
public Customer addCustomer(Customer customer) {
Customer newCustomer = cutomerRepository.save(customer);
return newCustomer;
}
最后,这是控制器:
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);
}
}
000和***的输出是无效的,这就是我插入的方式重视
任何帮助或想法?
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 ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要
@requestbody
在控制器的处理程序方法上You need
@RequestBody
on controller's handler method arg