orace 和spring结合 自动序列

来源:互联网 发布:sublime text 3 php 编辑:程序博客网 时间:2024/04/29 14:03

最近项目中需要用到自增序列  从000001 开始自增 这里记录下


在spring bean 配置文件配置

<bean id="accountnumber"
class="org.springframework.jdbc.support.incrementer.OracleSequenceMaxValueIncrementer">
<property name="incrementerName" value="ACCOUNTNUMBER_SEQ" />
<property name="dataSource" ref="dataSource" />
</bean>



图:


oracle 序列配置图:




测试代码:


public static void main(String[] args) {
ApplicationContext beanFactory = new ClassPathXmlApplicationContext("/spring/applicationContext.xml");
OracleSequenceMaxValueIncrementer incrementer = beanFactory.getBean(OracleSequenceMaxValueIncrementer.class);
System.out.println(incrementer.nextStringValue());

}


图:





0 0
原创粉丝点击