hash值生成表后缀(分表方案)
//businessId分表目标值,tableSize:表数量,tableSuffix:表后缀
public static String getTableSuffix(String businessId,long tableSize,String tableSuffix){
//获取目标hash值
long routeValue = Math.abs(businessId.hashCode());
long index = routeValue%tableSize;
String format = "%0"+(tableSuffix.length()-1)+"d";
return "_"+String.format(format, index);
}
public static void main(String[] args) {
String suffix = getTableSuffix("2222222222", 128, "-0000");
System.out.println(suffix);
}