以為必須按 SSH 分層:Action → Service → Dao,導致以為需為支付寶寫 Dao/Service。
WEB-INF/lib。public class AlipayAction extends ActionSupport {
public String pay() {
AlipayTradePagePayRequest request = new AlipayTradePagePayRequest();
request.setBizContent("...");
String form = alipayClient.pageExecute(request).getBody();
ServletActionContext.getResponse().getWriter().write(form);
return NONE;
}
public String notify() { /* 驗證回調 */ return NONE; }
}
struts.xml 映射 /alipay/pay、/alipay/notify。支付寶 SDK 封裝了簽名、網關請求、異步通知驗證,屬於「外部服務客戶端」,不涉及本地業務數據持久化,直接在控制層調用最簡潔。
整合第三方支付 SDK 時,Action 直接調用 SDK,無需強行套用 Service/Dao 分層。