1:在呼叫介面時候肯定會出現ab同事請求介面的問題,當時我在做訂單確認收貨時候就遇到了這種問題,所以我的解決辦法是加上鎖來解決,在這裡我選擇用lock 裡的reentrantlock(),在使用者請求方法時候,獲取到使用者id,放入lock,這也同乙個介面如果是2個相同使用者ab同時確認收貨時候,先到先處理,後來後處理,拿到鑰匙之後先進行乙個驗證,驗證此使用者是否已經收貨,預防一直在收貨,惡意介面呼叫,如果成功確認收貨那麼通過finally 來釋放鎖,同時移除鎖在lock裡的userid。這也就完成乙個確認收貨防止重複提交的乙個操作,如果是分布式的乙個介面,那麼可以參考一些分布式鎖的一些例子,此例子只當做單個伺服器做乙個防止重複提交。
private maplocks = new concurrenthashmap<>();
lock nlock = new reentrantlock();
lock lock = locks.putifabsent(cancelorderpar.getuserid(), nlock);
if (lock == null)
boolean removelock = false;
lock.lock();
try
}//根據訂單號查詢分享人id
string shareuserid=null;
if (!stringutils.isblank(findshareuseridbyparentid))
responsebasegainerdata=userclient.findroot(cancelorderpar.getuserid(),shareuserid);
string gainerid=null;
if (gainerdata!=null&&gainerdata.getdata()!=null)
removelock = true;
} finally
}
防止重複提交
在jsp頁面的form中,新增 然後在提交的action類中 suppresswarnings unchecked scope prototype controller results parentpackage default interceptorrefs value interceptorre...
防止重複提交
過濾器 repeatable 過濾器 構建可重複讀取inputstream的request submit註解 package com.medaxis.config.interceptor.annotation import j a.lang.annotation.自定義註解防止表單重複提交 inhe...
前後端分離重複提交 防止表單重複提交(二)
實現原理 1 頁面和後台同步存入乙個token,一旦重新整理頁面,此token都是會重新整理的 2 提交表單時,會帶上這個標識token 3 請求後台,將此token和後台存入的token比對 3.1 校驗token通過,成功提交表單,並移除token 3.2 校驗token不通過,給出前端提示,但...