分表的hash算法

public static void main(String[] args) throws Exception {
        SysConsole.out.println(findTables("student", "10w0", 20 ) ) ;
    }
  // 20张表 0-19
    public static String findTables(String tableName, String session, int tableNum) {
       int code =  session.hashCode();
       int table = ( code > 0 ? code : (-code) ) % tableNum;
       return tableName + "_" + table;
    }
posted @ 2022-04-24 14:34  郎小乐  阅读(129)  评论(0)    收藏  举报