Package Com.sc.util; Public classTableidgenerator {/** * Str required, shaped like SUA0000046 * beginindex required, the number of digits starting from the English character, for example SUA0000046, is starting from 3 * @param str * @param beginindex * @return*/ Public StaticString Generatorid (String str,intbeginindex) {String Leftstr=str.substring (0, beginindex);//first half English charactersString rigthtstr=str.substring (Beginindex);//first half digit character intLen=rigthtstr.length ();//total number of digits intRightint=integer.parseint (RIGTHTSTR) +1; String s=rightint+""; intlen1=s.length (); if(len>len1) { inti=len-len1; for(intj =0; J < I; J + +) {Leftstr+="0"; } leftstr+=Rightint; }Else{leftstr+=Rightint; } returnLeftstr; } Public Static voidMain (string[] args) {String s= Tableidgenerator.generatorid ("rw_0009",3); System. out. println (s); } }
Database primary key Generation tool class by fixed prefix