StringUtils.defaultIfEmpty()方法



public static String defaultIfEmpty(String str,
                                    String defaultStr)

如果str为空,则返回defaultStr。否则返回str;

附官方解释:

defaultIfEmpty

public static String defaultIfEmpty(String str,                                      String defaultStr)
Returns either the passed in String, or if the String is empty or 
null, the value of defaultStr.
 StringUtils.defaultIfEmpty(null, "NULL")  = "NULL"   StringUtils.defaultIfEmpty("", "NULL")    = "NULL"   StringUtils.defaultIfEmpty("bat", "NULL") = "bat"   StringUtils.defaultIfEmpty("", null)      = null   

Parameters:

str- the String to check, may be null

defaultStr- the default String to return if the input is empty ("") or null, may be null
Returns:
the passed in String, or the default
public class RequestBodyRoutePredicateFactory extends AbstractRoutePredicateFactory<RequestBodyRoutePredicateFactory.Config> { protected static final Log LOGGER = LogFactory.getLog(RequestBodyRoutePredicateFactory.class); private final List<HttpMessageReader<?>> messageReaders; public RequestBodyRoutePredicateFactory() { super(RequestBodyRoutePredicateFactory.Config.class); this.messageReaders = HandlerStrategies.withDefaults().messageReaders(); } public RequestBodyRoutePredicateFactory(List<HttpMessageReader<?>> messageReaders) { super(RequestBodyRoutePredicateFactory.Config.class); this.messageReaders = messageReaders; } public static final String REQUEST_BODY_ATTR = "requestBodyAttr"; @Override public AsyncPredicate<ServerWebExchange> applyAsync(Config config) { return exchange -> { if (!"POST".equals(exchange.getRequest().getMethodValue())&&!"PUT".equals(exchange.getRequest().getMethodValue())) { return Mono.just(true); } Object cachedBody = exchange.getAttribute(REQUEST_BODY_ATTR); if (cachedBody != null) { try { return Mono.just(true); } catch (ClassCastException e) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Predicate test failed because class in predicate does not match the cached body object", e); } } return Mono.just(true); } else { return ServerWebExchangeUtils.cacheRequestBodyAndRequest(exchange, (serverHttpRequest) -> ServerRequest.create(exchange.mutate().request(serverHttpRequest).build(), this.messageReaders).bodyToMono(String.class).defaultIfEmpty("").doOnNext((objectValue) -> { if(StringUtils.isBlank(objectValue)){ exchange.getAttributes().put(REQUEST_BODY_ATTR, JSON.toJSONString(exchange.getRequest().getQueryParams())); }else { exchange.getAttributes().put(REQUEST_BODY_ATTR, objectValue); } }).map((objectValue) -> true)); } };
06-08
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值