使用Redis让单号从001递增
生活随笔
收集整理的這篇文章主要介紹了
使用Redis让单号从001递增
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
最近項目遇到一個需求,單號從001開始遞增
下面用到了redis處理
代碼如下:
public String getId() {String key = "providerManager";Long incr = getIncr(key);if (incr == 0) {incr = getIncr(key);//從001開始}DecimalFormat df = new DecimalFormat("000");//三位序列號return df.format(incr); }public Long getIncr(String key) {RedisAtomicLong entityIdCounter = new RedisAtomicLong(key, redisTemplate.getConnectionFactory());Long increment = entityIdCounter.getAndIncrement();return increment; }?
?
效果如下圖所示
總結
以上是生活随笔為你收集整理的使用Redis让单号从001递增的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: php制作成绩单,PHP学生成绩查询及分
- 下一篇: 风扇转速/CPU温度监控工具推荐