{0}占位替换指定位置数据

场景:url路径需要替换指定参数

配置文件:多个参数用0,1,2...标记

living: /liveplay/{0}

finished: /playback/{0}?id={1}&liveId={2}

notStarted: /booklive/{0}?progId={1}&liveId={2}

domain: https://alpha.xxx.com

 java代码:MessageFormat.format()实现


    public void initH5Url(List<ResLiveBannerVO> bannerVOs) {
	bannerVOs.forEach(x -> {
	    if (LiveStatusEnum.NOT_START.getValue().equals(x.getStatus())) {
		x.setNotStartedUrl(domain + MessageFormat
				.format(notStartedUrl, x.getId().toString(), x.getId().toString(),
						x.getLiveId().toString()));
	    }
	    if (LiveStatusEnum.LIVING.getValue().equals(x.getStatus())) {
		x.setLivingUrl(domain + MessageFormat.format(livingUrl, x.getLiveId().toString()));
	    }
	    if (LiveStatusEnum.LIVE_END.getValue().equals(x.getStatus()) && Objects.nonNull(x.getLiveVideoId())) {
		x.setFinishedUrl(domain + MessageFormat
				.format(finishedUrl, x.getAuthorId().toString(), x.getLiveVideoId().toString(),
						x.getLiveId().toString()));
	    }
	});
    }

猜你喜欢

转载自blog.csdn.net/C18298182575/article/details/120966989
今日推荐