在项目local.properties里做出如下定义:
keygen.order.code.digits=8
keygen.order.code.start=00000000
keygen.order.code.numeric=true
keygen.order.code.template=$
core-spring.xml:
<bean id="orderCodeGenerator" class="de.hybris.platform.servicelayer.keygenerator.impl.PersistentKeyGenerator"> <property name="key" value="${keygen.order.code.name}"/> <property name="digits" value="${keygen.order.code.digits}"/> <property name="start" value="${keygen.order.code.start}"/> <property name="numeric" value="${keygen.order.code.numeric}"/> <property name="template" value="${keygen.order.code.template}"/>
效果如下:
修改定义后,如果不想重启Hybris server也能让他们立即生效,使用如下Java代码:
import de.hybris.platform.jalo.numberseries.* NumberSeriesManager nm = NumberSeriesManager.getInstance() def s = nm.getNumberSeries("order_code") println "Before: current: ${s.currentNumber} type: ${s.type} template: ${s.template}" nm.resetNumberSeries(s.key, "777", s.type, s.template ) def s2 = nm.getNumberSeries("order_code") println "After: current: ${s2.currentNumber} type: ${s2.type} template: ${s2.template}"
要获取更多Jerry的原创文章,请关注公众号"汪子熙":