「生成层次序号java」层次顺序编号

博主:adminadmin 2023-01-01 09:57:08 586

本篇文章给大家谈谈生成层次序号java,以及层次顺序编号对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。

本文目录一览:

生成自然数序号 的代码怎么写? 最好是用js或java写

你需要新建一个文件 名字为:id.properties 内容为:id=0

package base.util;

import java.io.FileNotFoundException;

import java.io.FileOutputStream;

import java.io.IOException;

import java.io.OutputStream;

import java.util.Properties;

import org.springframework.core.io.ClassPathResource;

public class IdConstructor {

private static Properties properties;

private static ClassPathResource cls;

static{

cls= new ClassPathResource("id.properties");//路径自定义,可以写全路径

properties = new Properties();

try {

properties.load(cls.getInputStream());

} catch (IOException e) {

System.out.println("文件不存在");

}

}

//读取文件的值

public static String getAttr(String key){

return properties.getProperty(key);

}

//修改文件的值

public static void setAttr(String key,String value) throws FileNotFoundException, IOException{

OutputStream fos = new FileOutputStream(cls.getFile());

properties.setProperty(key,value);

properties.store(fos, null);

fos.close();

}

//生成ID

public int getInt(){

String attr = getAttr("id");

int returnInt = 0;

try {

returnInt = Integer.valueOf(attr);

returnInt++;

setAttr("id",returnInt+"");

} catch (NumberFormatException e) {

returnInt = -1;

} catch (FileNotFoundException e) {

returnInt = -1;

} catch (IOException e) {

returnInt = -1;

}

return returnInt;

}

public static void main(String[] args) throws FileNotFoundException, IOException {

IdConstructor constructor = new IdConstructor();

System.out.println(constructor.getInt());

constructor.setAttr("id", "24");

System.out.println(constructor.getInt());

}

}

输出:

1

25

java中自动生成有规律的编号

public class Main {

private static long n = 1;

public static void main(String[] args) {

System.out.println(test(n));

System.out.println(test(n));

}

public static long test(long l) {

String str = new SimpleDateFormat("yyyyMM")

.format(new java.util.Date());

long m = Long.parseLong((str)) * 10000;

long ret = m + l;

n = l + 1;

return ret;

}

}

java自动生成的序列号

添加前进页面的时候就把数据库中最大的那个序列号拿出来,加上1在页面显示,然后传道后台保存,修改的话到数据库验证下序列号,存在的话就不给保存。

java 按天生成序号

提供2个思路:

1:存取最后一次序列号的日期,每次生成序号的时候取该日期和当前日期对比不同则重新计数,并将本次日期覆盖为最后一次序列号的日期;

2:如果用数据库存储的话可以考虑每次去数据库查询是否有like当前日期的序号,没有则重新计数;

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(dateeriqi1){

a=1;//如果日期变大则初始化订单号

}

}

String str3=null;

if(a=0a=9){

str3="00"+String.valueOf(a);

}else if(a=10a=99){

str3="0"+String.valueOf(a);

}else if(a=100a=999){

str3=String.valueOf(a);

}

String instock_number=str1+str2+str3;

instockEntity.setInstock_number(instock_number);

instockService.add(instockEntity);

m=a+1;

}

关于生成层次序号java和层次顺序编号的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。