如何解决主键的连续自增

解决方案是采用文件暂存的方式。
从1开始到99后重新归一循环。
	public int getSeqNo() throws IOException {
		int seqNo = 1;
		File file = new File("seqNo");
		if (!file.exists()) {
			file.createNewFile();
		} else {
			Scanner in = new Scanner(new FileReader(file));
			if (in.hasNextInt()) {
				seqNo = in.nextInt();
				if (seqNo < 99) {
					seqNo++;
				} else if (seqNo == 99) {
					seqNo = 1;
				}
			}
			in.close();
		}

		PrintWriter out = new PrintWriter("seqNo");
		out.print(seqNo);
		out.close();
		return seqNo;
	}

你可能感兴趣的:(主键)