hearthstone database Summary
Preface
This is a full-stack project based on a front-end and back-end separation architecture. The back-end tech stack includes Spring Boot + MyBatis + MySQL. The front-end is built with Vue 3. After completion, the project was deployed on AWS cloud services, running on Ubuntu, with Nginx configured as a reverse proxy.
The entire project—from collecting the dataset, cleaning the data, integrating the database, to finally deploying it to the server—took approximately 10 days. The actual front-end and back-end development did not take very long, nor did it involve particularly complex technologies. Most of the time was spent on database cleaning and integration.
The metadata came from a third-party Hearthstone website API (many thanks to them). However, after retrieving the metadata, it could not be used directly due to dirty data, redundant entries, and formatting inconsistencies. Fixing these issues took about 3–4 days.
This article summarizes and reviews the issues encountered and the major workload involved throughout the development process.
Below is a screenshot of the IDEA project structure:
1 | <img src="https://pics.findfuns.org/backend-overview.png" alt="back" style="zoom:33%;" /> |
The entire back-end project follows the classic Spring MVC architecture: Controller–Service–Mapper layers. POJO classes and custom TypeHandlers were also designed. The custom TypeHandler is used to handle mappings between database query results and Java objects when default mappings are insufficient.
POJO
Let’s first talk about the POJO classes. To accommodate different card types and their various attributes, the POJO classes were carefully designed, including inheritance relationships, enum classes, and data types.
1 | <img src="https://pics.findfuns.org/pojo-hierarchical-diagram.png" alt="z" style="zoom:33%;" /> |
The Card class is the base class for all cards. Every card type extends the Card class. It contains the fundamental attributes shared by all cards.
1 | package com.zzb.hearthstoneDB.pojo; |
There are six subclasses of Card: Spell, Hero, HeroPower, Location, Weapon, and Minion, corresponding to six card types: spells, hero cards, hero powers, locations, weapons, and minions.
For example, the design of the Minion class:
1 | package com.zzb.hearthstoneDB.pojo; |
Several attributes such as Rarity, Race, CardClass, and SpellSchool have a fixed set of possible values, making them well-suited for enum classes.
For example, the SpellSchool enum:
1 | package com.zzb.hearthstoneDB.pojo; |
Controller
The Controller layer is responsible for route mapping, extracting parameters from URLs, and passing them to the Service layer.
1 | package com.zzb.hearthstoneDB.controller; |
@RestController is a composite annotation that includes both @Controller and @ResponseBody.@Controller marks the class as a Spring MVC controller, and @ResponseBody ensures that the return value is written directly to the HTTP response body in JSON format.
@Autowired automatically injects the Service component.
@RequestMapping defines the base route. Note that the base route does not start with ‘/‘, which differs from method-level routes.
A typical controller method looks like this:
1 |
|
@GetMapping specifies that the method handles GET requests and defines the corresponding route.
@RequestParam extracts query parameters from a GET request, such as:
1 | localhost:8080/minion?cost=9&rarity=RARE |
The required parameter defaults to true. If not provided, Spring throws a MissingServletRequestParameterException and returns HTTP 400. Setting it to false allows null values.
Service
The Service layer packages the parameters from the Controller into corresponding POJO objects and passes them to the Mapper layer for querying.
1 | package com.zzb.hearthstoneDB.service; |
Example Service method:
1 | public List<Card> selectMinions(String name, Integer cost, Integer attack, |
Mapper
The Model layer uses MyBatis as the ORM framework. In MyBatis, the Mapper interface defines SQL mappings.
XML configuration files are placed under the resources directory, and the folder structure must exactly match the Java package structure.
Example Mapper interface:
1 | package com.zzb.hearthstoneDB.mapper; |
XML Basic Structure
1 |
1 | <mapper namespace="com.zzb.hearthstoneDB.mapper.CardMapper"> |
resultMap Example
1 | <resultMap id="cardResultMap" type="com.zzb.hearthstoneDB.pojo.Card"> |
Dynamic SQL Example
1 | <select id="selectMinion" resultMap="minionResultMap"> |
Database Design
1 | <img src="https://pics.findfuns.org/hearthstone-database-diagram.png" style="zoom:33%;" /> |
The database consists of six tables, each corresponding to a specific card type. All tables use id as the primary key.







