参考文章:(1条消息) springBoot参数联合校验,自定义分组校验_yuhui666666的博客-CSDN博客_springboot 参数联合校验https://blog.csdn.net/y666666y/article/details/118482863
一、自定义分组完成微信支付,申请退款参数二选一
@GroupSequenceProvider(value = NativeRefundSequenceProvider.class) @Data public class NativeRefundDTO { @Valid @NotNull(message = "微信支付基本配置必传") private WxPaybase wxPaybase; @NotBlank(message = "微信支付订单号必传",groups = WhenOutTradeNoIsNull.class) @Length(min = 1, max = 32, message = "微信支付订单号长度需要在1和32之间",groups = WhenOutTradeNoIsNull.class) private String transaction_id; @NotBlank(message = "商户订单号必传",groups = WhenTransactionIdIsNull.class) @Length(min = 6, max = 32, message = "商户订单号长度需要在6和32之间",groups = WhenTransactionIdIsNull.class) private String out_trade_no; @NotBlank(message = "商户退款单号必传") @Length(min = 1, max = 64, message = "商户退款单号长度需要在1和64之间") private String out_refund_no; @Length(min = 1, max = 80, message = "退款原因长度需要在1和80之间") private String reason; @Length(min = 8, max = 256, message = "退款结果回调url长度需要在8和256之间") private String notify_url; @Length(min = 1, max = 32, message = "退款资金来源长度需要在1和32之间") private String funds_account; @Valid private NativeRefundAmount amount; @Valid private Listgoods_detail; public interface WhenTransactionIdIsNull {} public interface WhenOutTradeNoIsNull {} }
public class NativeRefundSequenceProvider implements DefaultGroupSequenceProvider{ @Override public List > getValidationGroups(NativeRefundDTO dto) { List > defaultGroupSequence = new ArrayList<>(); defaultGroupSequence.add(NativeRefundDTO.class); if(Objects.nonNull(dto)){ //微信支付订单号为null,group =WhenTransactionIdIsNull 的校验注解生效 if(Objects.isNull(dto.getTransaction_id()) ){ defaultGroupSequence.add(NativeRefundDTO.WhenTransactionIdIsNull.class); } //商户订单号为null,group = WhenOutTradeNoIsNull 的校验注解生效 if(Objects.isNull(dto.getOut_trade_no())){ defaultGroupSequence.add(NativeRefundDTO.WhenOutTradeNoIsNull.class); } } return defaultGroupSequence; } }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)