CreateOrderReq传入参数校验不能为空,为什么没生效呢?
package com.imooc.mall.controller;
import com.imooc.mall.common.ApiRestResponse;
import com.imooc.mall.model.request.CreateOrderReq;
import com.imooc.mall.service.OrderService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import javax.validation.Valid;
@RestController
public class OrderController {
@Resource
OrderService orderService;
@PostMapping("order/create")
public ApiRestResponse create(@Valid @RequestBody CreateOrderReq createOrderReq){
String orderNo = orderService.create(createOrderReq);
return ApiRestResponse.success(orderNo);
}
}package com.imooc.mall.model.request;
import javax.validation.constraints.NotNull;
public class CreateOrderReq {
@NotNull(message = "收件人姓名不能为null")
private String receiverName;
@NotNull(message = "收件人手机号不能为null")
private String receiverMobile;
@NotNull(message = "收件人地址不能为null")
private String receiverAddress;
private Integer orderStatus;
private Integer postage;
private Integer paymentType;
public String getReceiverName() {
return receiverName;
}
public void setReceiverName(String receiverName) {
this.receiverName = receiverName;
}
public String getReceiverMobile() {
return receiverMobile;
}
public void setReceiverMobile(String receiverMobile) {
this.receiverMobile = receiverMobile;
}
public String getReceiverAddress() {
return receiverAddress;
}
public void setReceiverAddress(String receiverAddress) {
this.receiverAddress = receiverAddress;
}
public Integer getOrderStatus() {
return orderStatus;
}
public void setOrderStatus(Integer orderStatus) {
this.orderStatus = orderStatus;
}
public Integer getPostage() {
return postage;
}
public void setPostage(Integer postage) {
this.postage = postage;
}
public Integer getPaymentType() {
return paymentType;
}
public void setPaymentType(Integer paymentType) {
this.paymentType = paymentType;
}
}
6
收起
正在回答 回答被采纳积分+1
1回答
2023版Java工程师
- 参与学习 人
- 提交作业 8788 份
- 解答问题 9886 个
综合就业常年第一,编程排行常年霸榜,北上广深月薪过万! 不需要基础,无需脱产即可学习,只要你有梦想,想高薪! 全新升级:技术栈升级(包含VUE3.0,ES6,Git)+项目升级(前后端联调与功能升级)
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星