Building a Graduate Employment Management WeChat Mini Program with Spring Boot, Vue.js, and UniApp
Technology Stack Overview
Backend Framework: Spring Boot
Spring Boot streamlines development by embedding servers like Tomcat and enabling automatic configuration based on dependencies. It offers feautres such as Spring Data and Spring Security for rapid application building.
Example code for a basic Spring Boot application:
package com.example.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@SpringBootApplication
@RestController
public class AppLauncher {
public static void main(String[] args) {
SpringApplication.run(AppLauncher.class, args);
}
@GetMapping("/greeting")
public String sendGreeting() {
return "Welcome to the system!";
}
}
This class initializes a Spring Boot app with a REST endpoint returning a greeting message.
Frontend Framework: Vue.js
Vue.js utilizes a virtual DOM for efficient UI updates and supports reactive data binding and component-based architecture.
Sample Vue.js implementation:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Vue Example</title>
<script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
</head>
<body>
<div id="vueApp">
<p>{{ greetingText }}</p>
<button v-on:click="updateGreeting">Update Text</button>
</div>
<script>
new Vue({
el: '#vueApp',
data: {
greetingText: 'Initial Vue message'
},
methods: {
updateGreeting: function() {
this.greetingText = 'Updated Vue content';
}
}
});
</script>
</body>
</html>
This code binds data to the UI and updates it dynamically on button click.
Persistence Layer: MyBatis
MyBatis separates SQL from Java code using XML or annotations, supporting dynamic SQL and caching to enhance performance.
System Testing Approach
Testing ensures system reliability by validating functionality and user requirements.
Functional Testing
Black-box testing is conducted on modules like login and user management with test cases.
Login test case example:
| Input Data | Expected Outcome | Actual Result | Analysis |
|---|---|---|---|
| Username: admin, Password: correct, Captcha: valid | Login success | Login succsess | Pass |
| Username: admin, Password: incorrect, Captcha: valid | Password error | Password error | Pass |
User management test cases cover add, edit, and delete operations with similar tables.
Testing Conclusion
Comprehensive testing confirms the system meets design specifications, with all functions operating correctly and user-centric scenarios validated.
Code Implementation Examples
Authentication and Token Management
Java code for login and token generation:
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.util.Calendar;
import java.util.Date;
@RestController
public class AuthController {
@PostMapping("/authenticate")
public Response login(@RequestParam String user, @RequestParam String pass, HttpServletRequest req) {
UserEntity foundUser = userRepo.findByUsername(user);
if (foundUser == null || !foundUser.getPassword().equals(pass)) {
return Response.error("Invalid credentials");
}
String authToken = tokenService.createToken(foundUser.getId(), foundUser.getUsername(), "users", foundUser.getRole());
return Response.ok().addData("token", authToken);
}
}
@Service
public class TokenService {
public String createToken(Long uid, String uname, String table, String role) {
TokenEntity existingToken = tokenRepo.findByUserIdAndRole(uid, role);
String newToken = RandomUtil.generateString(32);
Calendar expiry = Calendar.getInstance();
expiry.add(Calendar.HOUR, 1);
if (existingToken != null) {
existingToken.setToken(newToken);
existingToken.setExpiryTime(expiry.getTime());
tokenRepo.save(existingToken);
} else {
tokenRepo.save(new TokenEntity(uid, uname, table, role, newToken, expiry.getTime()));
}
return newToken;
}
}
This handles user authentication and issues tokens valid for one hour.
Authorization Interceptor
Interceptor for token validatoin:
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@Component
public class AuthInterceptor implements HandlerInterceptor {
private static final String TOKEN_HEADER = "Auth-Token";
@Override
public boolean preHandle(HttpServletRequest req, HttpServletResponse resp, Object handler) throws Exception {
if (handler instanceof HandlerMethod) {
HandlerMethod method = (HandlerMethod) handler;
if (method.getMethodAnnotation(NoAuthRequired.class) != null) {
return true;
}
}
String token = req.getHeader(TOKEN_HEADER);
if (token == null || token.isEmpty()) {
resp.setStatus(401);
resp.getWriter().write("Authentication required");
return false;
}
TokenEntity tokenData = tokenService.validateToken(token);
if (tokenData == null) {
resp.setStatus(401);
resp.getWriter().write("Invalid token");
return false;
}
req.getSession().setAttribute("user", tokenData);
return true;
}
}
This checks tokens for protected endpoints and manages session data.
Database Schema Example
SQL for a sample table:
CREATE TABLE item (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
item_name VARCHAR(100) NOT NULL,
cost DECIMAL(10,2) NOT NULL,
details VARCHAR(200),
quantity INT NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
modified_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB COMMENT='Item records';
INSERT INTO item (item_name, cost, details, quantity) VALUES
('Laptop Model X', 1200.00, 'High-performance laptop', 30),
('Tablet Model Y', 300.00, 'Portable tablet device', 50);
This defines a product-like table with fields for name, price, description, stock, and timestamps.