Spring Boot API Project Seed: Best Practices, Code Templates, and Utilities
This article introduces a Spring Boot API project seed that combines MyBatis, a generic Mapper plugin, and PageHelper, offering a ready‑to‑use project structure, unified response handling, exception processing, code generation tools, and simple signature authentication to accelerate backend development.
Introduction – The author shares experiences from building several small‑to‑medium API projects using Spring Boot together with MyBatis, a generic Mapper plugin, and the PageHelper pagination plugin. They found this stack comfortable and well received by the team, and they summarize useful practices for future projects.
Motivation – Before starting a new API project, developers usually set up the project, add dependencies, and configure frameworks. To speed up development, common utilities such as unified response wrappers, global exception handling, request signature verification, basic CRUD abstractions, and code generators are often created. Re‑creating these steps for each similar project wastes time, so the author abstracted the common parts into a reusable seed project that can be cloned and extended.
Features & Provision – The seed provides a best‑practice project structure, streamlined configuration files, and a minimal POM. It includes:
Unified API response wrapper (
public class Result { private int code; private String message; private Object data; /* getters/setters */ })
Result code enumeration mirroring HTTP status semantics (
public enum ResultCode { SUCCESS(200), FAIL(400), UNAUTHORIZED(401), NOT_FOUND(404), INTERNAL_SERVER_ERROR(500); /* ... */ })
Result generation utilities (
public class ResultGenerator { public static Result genSuccessResult() { return new Result().setCode(ResultCode.SUCCESS).setMessage("SUCCESS"); } /* overloads for data and failure */ })
Global exception resolver that maps different exception types to appropriate ResultCode values and logs detailed error information.
Common CRUD service interface (
public interface Service<T> { void save(T model); void deleteById(Integer id); T findById(Integer id); List<T> findAll(); /* ... */ })
Code generator that, given a table name, can produce Model, Mapper, MapperXML, Service, ServiceImpl, and Controller classes (POST‑style or RESTful templates).
Simple request‑signature interceptor for basic authentication, with a fallback to more robust solutions such as JWT.
Technical Stack – The seed integrates MyBatis, the generic Mapper plugin, PageHelper for pagination, Druid Spring Boot Starter for connection pooling and monitoring, and Fastjson for high‑performance JSON serialization.
Technology Selection & Documentation – References are provided for Spring Boot, MyBatis, the Mapper plugin, PageHelper, Druid, and Fastjson, allowing developers to explore each component in depth.
The project source code and usage documentation are available at https://github.com/lihengming/spring-boot-api-project-seed . Users are encouraged to submit issues or pull requests for improvements.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Java Captain
Focused on Java technologies: SSM, the Spring ecosystem, microservices, MySQL, MyCat, clustering, distributed systems, middleware, Linux, networking, multithreading; occasionally covers DevOps tools like Jenkins, Nexus, Docker, ELK; shares practical tech insights and is dedicated to full‑stack Java development.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
