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回答
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星