瀏覽代碼

Sequence 新增 mac 判断,分页 pageHelper 模式新增 freeTotal() 方法

hubin 8 年之前
父節點
當前提交
b9214a5046

+ 11 - 6
src/main/java/com/baomidou/mybatisplus/plugins/pagination/PageHelper.java

@@ -35,8 +35,6 @@ public class PageHelper {
      * <p>
      * 获取总条数
      * </p>
-     *
-     * @return
      */
     public static int getTotal() {
         if (isPageable()) {
@@ -46,12 +44,21 @@ public class PageHelper {
         }
     }
 
+    /**
+     * <p>
+     * 释放资源并获取总条数
+     * </p>
+     */
+    public static int freeTotal() {
+        int total = getTotal();
+        remove();// 释放资源
+        return total;
+    }
+
     /**
      * <p>
      * 获取分页
      * </p>
-     *
-     * @return
      */
     public static Pagination getPagination() {
         return LOCAL_PAGE.get();
@@ -61,8 +68,6 @@ public class PageHelper {
      * <p>
      * 设置分页
      * </p>
-     *
-     * @param page
      */
     public static void setPagination(Pagination page) {
         LOCAL_PAGE.set(page);

+ 4 - 2
src/main/java/com/baomidou/mybatisplus/toolkit/Sequence.java

@@ -115,8 +115,10 @@ public class Sequence {
                 id = 1L;
             } else {
                 byte[] mac = network.getHardwareAddress();
-                id = ((0x000000FF & (long) mac[mac.length - 1]) | (0x0000FF00 & (((long) mac[mac.length - 2]) << 8))) >> 6;
-                id = id % (maxDatacenterId + 1);
+                if (null != mac) {
+                    id = ((0x000000FF & (long) mac[mac.length - 1]) | (0x0000FF00 & (((long) mac[mac.length - 2]) << 8))) >> 6;
+                    id = id % (maxDatacenterId + 1);
+                }
             }
         } catch (Exception e) {
             logger.warn(" getDatacenterId: " + e.getMessage());