자바 에서 자동 으로 인 코딩 생 성, 예 를 들 어 18 비트, 20 비트 등

2100 단어 자바
    /***
     * 
     * getCommonBh:(       :  (       N +    (     )+    sequence :00001)). 
* @author syzhao * @param prefix * @param timeFormt , * @param sequenceName sequence * @param length sequence %08d:8 0 * @return * @since JDK 1.6 */ public String getCommonBh(String prefix, String timeFormt, String sequenceName, String length) { String datenumber = ""; if (StringUtils.isNotEmpty(timeFormt)) { datenumber = DateUtils.doFormatDate(new Date(), timeFormt); } if (StringUtils.isEmpty(length)) { length = "8"; } String seqStr = getSequenceByName(sequenceName, length); return new StringBuilder(prefix).append(datenumber).append(seqStr).toString(); } /** * * getSequenceByName:( sequence ).
* @author syzhao * @param sequenceName sequence * @param length , ::8 0 * @return String sequence * @since JDK 1.6 */ public String getSequenceByName(final String sequenceName, final String length) { if (StringUtils.isBlank(sequenceName)) { return ""; } else { return (String)this.getHibernateTemplate().execute(new HibernateCallback() { public Object doInHibernate(Session session) throws SQLException { Query query = getSession().createSQLQuery(" SELECT " + sequenceName + ".nextval from dual"); BigDecimal seq = (BigDecimal)query.uniqueResult(); if (seq != null) { return String.format("%0" + length + "d", seq.longValue()); } else { return "001"; } } }); } }

좋은 웹페이지 즐겨찾기