1. java自动生成编号
private static int m=1;//全局静态变量,(必须static修饰)每调用一次方法自增1
public String add(){
addin(m);
return "addTiao";
}
public void addin(int a){
String str1="A";
Date date=new Date();
String str2=new SimpleDateFormat("yyyyMMdd"). format(date);//自动生成日期
int datee=Integer.parseInt(str2);
inlist=instockService.getInListDown();//按降幂排序
instockEntity=(InstockEntity) inlist.get(0);
String ss=instockEntity.getInstock_number();//得到最大日期
if(ss!=null){
String riqi=ss.substring(1, 9);
int riqi1=Integer.parseInt(riqi);
if(datee>riqi1){
a=1;//如果日期变大则初始化订单号
}
}
String str3=null;
if(a>=0&&a<=9){
str3="00"+String.valueOf(a);
}else if(a>=10&&a<=99){
str3="0"+String.valueOf(a);
}else if(a>=100&&a<=999){
str3=String.valueOf(a);
}
String instock_number=str1+str2+str3;
instockEntity.setInstock_number(instock_number);
instockService.add(instockEntity);
m=a+1;
}
2. 编号以0000-9999这种方式自动生成,java类应该怎么写
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println(getNumber(9999));
}
public static String getNumber(int num)
{
num++;
String result = "";
switch ((num+"").length()) {
case 1:
result = "000" + num;
break;
case 2:
result = "0" + num;
break;
case 3:
result = "0" + num;
break;
case 4:
result = "" + num;
break;
// 此处代表编号已经超过了9999,从0重新开始
default:
result = "0000";
break;
}
return result;
}
3. java濡备綍镙规嵁镞ユ湡镊锷ㄧ紪鍙
瑕佹牴鎹镞堕棿鐢熸垚缂栧彿锛岄栧厛瑕佺煡阆撶紪鍙风殑鏂瑰纺锛屾瘆濡傚彧鏄鎶婃椂闂翠腑镄勭﹀彿铡绘帀鍙浠ヤ娇鐢⊿impleDateFromat杩欎釜绫
//鍏跺疄链夊緢澶氭儏鍐甸兘鍙浠ョ敤瀹冭В鍐筹纴鍙闇瑕佹敼鍏朵腑镄勬牸寮
//澶ф傛槸杩欐牱锛屾坠鍐欑殑浠g爜
Stringbh=newSimpleDateFormate("yyyyMMddHHmmss").format(newDate());
//寰楀埌201806061331
濡傛灉闇瑕佸嶆潅镣圭殑锛屽彲浠ヤ娇鐢–alendar杩欎釜绫伙纴銮峰彇闇瑕佺紪鍙风殑鏁版嵁杩涜岀紪鍙
Calendarc=Calendar.getInstance();
c.setTime(newDate());
//阃氲繃get鏂规硶銮峰彇鍏蜂綋镄勫硷纴骞淬佹湀銆佹棩銆佹椂銆佸垎銆佺掋佹槦链绛
c.get(Calendar.HOUR_OF_DAY);//銮峰缑灏忔椂锛屽叾浠栫殑甯搁噺鍙浠ュ湪瀹樻柟API镆ユ垒锛屾垨钥呯栌搴︺怌alendar.java甯搁噺銆