JSON:是一种轻量级的数据交换格式
@requestBody可以将请求体中的JSON字符串绑定到相应的bean上,当然,也可以将其分别绑定到对应的字符串上。
这里就是JSON数据赋值给了Payment类的属性,并且一一对应的赋值。
@RestController
@Slf4j
public class PaymentController {
@Autowired
private PaymentServiceImpl paymentService;
@PostMapping(value = "/payment/create")
// JSON:是一种轻量级的数据交换格式
// @requestBody可以将请求体中的JSON字符串绑定到相应的bean上,当然,也可以将其分别绑定到对应的字符串上。
// 这里就是JSON数据赋值给了Payment类的属性,并且一一对应的赋值。
public CommentResult create(@RequestBody Payment payment){
int i = paymentService.create(payment);
log.info("******插入结果"+i);
if (i>0){
return new CommentResult(200,"插入数据库成功",i);
}else {
return new CommentResult(444,"插入数据库失败",null);
}
}
@GetMapping(value = "/payment/get/{id}")
public CommentResult getPaymentById(@PathVariable("id")Long id){
Payment payment = paymentService.getPaymentById(id);
log.info("******结果"+payment);
if (payment!=null){
return new CommentResult(200,"成功",payment);
}else {
return new CommentResult(444,"查询失败",null);
}
}
}