Java短连接生成工具-思路-这里只是模拟一下
package com.csrs.trans.shorturl;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
/**
*
* @title: 短连接生成工具
* @author: wll
* @since: 2021-2-9 16:34:13
*/
public class ShortUrl {
static Map<String, String> urlMap = new HashMap<String, String>();
public static void main(String[] args) {
String url = "http://yueroon.date/xxxxxxxxxxxxxxxx/xxxxxx/xxxxxx/xxxxxx/xxxxxx/xxxxxx/xxxxxx/xxxxxxxxxxxxx/index.html";
String transShortUrl = transShortUrl(url);
System.out.println("转换后:" + transShortUrl);
String longlString = openShortUrl(transShortUrl);
System.out.println("转换前:" + longlString);
}
private static String openShortUrl(String shortUrl) {
return urlMap.get(shortUrl);
}
/**
* 转换为短连接
*
* @param url
*/
private static String transShortUrl(String url) {
String resultStr = "htttp://www.baidu.com/" + (UUID.randomUUID().toString().replace("-", ""));
urlMap.put(resultStr, url);
return resultStr;
}
}