Every time receiving specific post request from client, server should produce an unique integer to generate a link(uri: website/question/id/details) and store the integer as index(primary key) in database. I've tried int idForUri = UniqueInteger.uri.incrementAndGet();
But this doesn't work if server reboots. How can I fix this?
class UniqueInteger {
public static AtomicInteger uri = new AtomicInteger(212043);
}
Add
table article
------------
id int(11) unsigned auto_increment primary key
title varchar(50)
content text
uri varchar(50)
Every specific post request from browser cause server to produce a new uri. User visit that page by the uri, which consists of "website/question/id/details"(id is the primary key). But without knowing the new id, the uri is also unknown. For example, 21000 is currently the max id existed in table article. So insert into article(title, content, uri) values (?, ?, 'website/questions/21001/details')
is needed. But server doesn't know the value of 21001 because of auto-increment(maybe leads to a sql select
statement before executing insert
).
Users by typing specific uri in browser to visit every article page, a HTTP request. Server should know which article to be sent just by the receiving link. So I add id to uri(just like the uri in SO, which is questions/question-id/title).Then by parsing the id filed in uri, server can locate the specific article.
How to fix the design?