public String getID(String orgin)
{
int i=Integer.parseInt(orgin);
i++;
if (i>99999) i=1;String ID=String.valueOf(i);
if (ID.length()==1)
ID="0000"+ID;
else if (ID.length()==2)
ID="000"+ID;
else if (ID.length()==3)
ID="00"+ID;
else if (ID.length()==4)
ID="0"+ID;return ID;
}
{
int i=Integer.parseInt(orgin);
i++;
if (i>99999) i=1;String ID=String.valueOf(i);
if (ID.length()==1)
ID="0000"+ID;
else if (ID.length()==2)
ID="000"+ID;
else if (ID.length()==3)
ID="00"+ID;
else if (ID.length()==4)
ID="0"+ID;return ID;
}
private static final String DEFUAL_MIN_SN = "000001";
private static final String DEFUAL_MAX_SN = "999999";
private String minSN = DEFUAL_MIN_SN;
private String maxSN = DEFUAL_MAX_SN; public SerialNoGenerator() { super();
} public String getMaxSN() {
return this.maxSN;
} public void setMaxSN(String maxSN) {
this.maxSN = maxSN;
} public String getMinSN() {
return this.minSN;
} public void setMinSN(String minSN) {
this.minSN = minSN;
}
public String getNextSN(String thisSN) {
if(thisSN == null) {
thisSN = "";
}
if(thisSN.length() != this.minSN.length()) {
throw new IllegalArgumentException("不正确的原始序列号!");
}
if(thisSN.compareTo(this.maxSN) >= 0) {
return this.minSN;
}
return getNextSN(thisSN, thisSN.length());
}
public String getNextSN(String thisSN, int snLength) {
if(thisSN == null) {
thisSN = "0";
}
int nextInt = 0;
try {
nextInt = Integer.parseInt(thisSN) + 1;
}
catch(NumberFormatException e) {
throw new IllegalArgumentException("不正确的原始序列号!");
}
int thisLength = (nextInt+"").length();
StringBuffer tmp = new StringBuffer();
for(int i=thisLength; i<snLength; i++) {
tmp.append("0");
}
tmp.append(nextInt);
return tmp.toString();
}
public static void main(String[] args) {
SerialNoGenerator generator = new SerialNoGenerator();
System.out.println(generator.getNextSN("001011"));
}
}
http://community.csdn.net/Expert/TopicView3.asp?id=4816106乱码还原问题!
http://community.csdn.net/Expert/TopicView3.asp?id=4813786关于javabean反射代理的问题
http://community.csdn.net/Expert/TopicView3.asp?id=4813935