Backend Development 10 min read

Integrating Alipay Payment into an SSM (Spring + Spring MVC + MyBatis) Application

This tutorial walks through the complete process of configuring a sandbox Alipay environment, setting up keys and URLs, defining the required database schema, and integrating Alipay payment flow into an SSM‑based Java backend with detailed code examples and troubleshooting tips.

Top Architect
Top Architect
Top Architect
Integrating Alipay Payment into an SSM (Spring + Spring MVC + MyBatis) Application

The article introduces a step‑by‑step guide for implementing Alipay payment within an SSM (Spring, Spring MVC, MyBatis) project, beginning with downloading the official Alipay demo, importing it into Eclipse, and configuring the AlipayConfig class with app_id, gateway URL, and generated RSA keys.

It then explains how to set the asynchronous notification URL (notify_url) and synchronous return URL (return_url) for the local development server, providing example URLs such as http://localhost:8080/alipay.trade.page.pay-JAVA-UTF-8/notify_url.jsp and http://localhost:8080/alipay.trade.page.pay-JAVA-UTF-8/return_url.jsp .

The guide defines the required MySQL tables (user, flow, orders, product) and supplies the full DDL statements inside CREATE TABLE blocks, showing column types, primary keys, and comments.

DAO interfaces are presented, for example the OrdersMapper with CRUD methods, followed by the OrdersService interface that declares methods for saving orders, updating order status, and retrieving orders by ID.

Controller code for the Alipay payment flow is shown, illustrating how to build an AlipayTradePagePayRequest , set business parameters (out_trade_no, total_amount, subject, body, timeout_express), and invoke alipayClient.pageExecute to obtain the payment page HTML.

JSP pages for product listing (products.jsp) and order creation are included, demonstrating the use of JSTL tags to iterate over products and generate purchase links, as well as hidden fields for context path handling.

Testing steps are described: running the application, accessing http://localhost:8080/ , creating an order, selecting Alipay, and verifying successful payment and signature verification in the sandbox environment.

A troubleshooting section notes that sandbox and production gateways differ, and provides the correct gateway configuration to avoid app_id errors.

Finally, the article shares download links for the complete source code (GitHub repository and Baidu Cloud) and encourages readers to like, share, and join the author’s architecture community for additional resources.

BackendJavaspringMyBatisPayment IntegrationAlipaySSM
Top Architect
Written by

Top Architect

Top Architect focuses on sharing practical architecture knowledge, covering enterprise, system, website, large‑scale distributed, and high‑availability architectures, plus architecture adjustments using internet technologies. We welcome idea‑driven, sharing‑oriented architects to exchange and learn together.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.