We can use Oracle's growth in MyBatis, and we can use configuration files and Java code to get the maximum value of the current self increase.
First, you need to create a self augmentation in Oracle, as follows.
CREATE SEQUENCE " commontrade". Ucf_recharge_suborder_seq " minvalue 10000000000 MAXVALUE 99999999999 INCREMENT by 1 START with 10000007200 CACHE N Oorder nocycle;
Step two: Use Spring's support configuration for Oracle sequences. Need to be configured in Applicationcontext.xml.
<bean id= "Oraclesequencemaxvalueincrementer"
class= " Org.springframework.jdbc.support.incrementer.OracleSequenceMaxValueIncrementer ">
<property name=" Incrementername "value=" "></property>
<property name=" DataSource "ref=" DataSource "></" Property>
</bean>
Step three: Write the tool class that gets the sequence.
Import org.springframework.beans.factory.annotation.Autowired;
Import Org.springframework.jdbc.support.incrementer.OracleSequenceMaxValueIncrementer;
Import Org.springframework.stereotype.Service;
Import Com.ucf.trade.util.enums.TradeEnum;
@Service public
class Sequencegenerator {
private static final String Ucf_recharge_trade_order_seq = "ucf_ Recharge_trade_order_seq ";
@Autowired public
oraclesequencemaxvalueincrementer oraclesequencemaxvalueincrementer;
public string Nextrechargeorderseq (string bizproduct, String txntype) {
Oraclesequencemaxvalueincrementer.setincrementername (UCF_RECHARGE_TRADE_ORDER_SEQ);
String currval = Oraclesequencemaxvalueincrementer.nextstringvalue ();
Return Timeutil.getcurrentdatetime14 () +bizproduct+ txntype + currval;
20140328175835 10000002814 Total 30 bits
}
Fourth Step: Use
Inject this tool class as a service
@Autowired public
Sequencegenerator sequencegenerator;
Add in the method you want
String ID =sequencegenerator.nextrechargeorderseq ();
By using the sequence in Oracle, we can use this sequence to stitch up some meaningful numbers.