The backend is implemented using the Spring Boot framework, which simplifies configuration through auto-configuration and convention-over-configuration principles. It embeds a web server (e.g., Tomcat) for easy deployment as an executable JAR. MyBatis integrates with Spring via @MapperScan to enable database operations.
package com;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
@SpringBootApplication
@MapperScan(basePackages = {"com.dao"})
public class Application extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(Application.class);
}
}
The frontend leverages Vue.js for building responsive user interfaces with reactive data binding and component-based architecture, enabling modular and maintainable UI development.
A core controller handles user authentication, registration, session management, and CRUD operations:
package com.controller;
import java.util.*;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.entity.YonghuEntity;
import com.service.YonghuService;
import com.service.TokenService;
import com.utils.R;
@RestController
@RequestMapping("/yonghu")
public class UserController {
@Autowired
private YonghuService userService;
@Autowired
private TokenService tokenService;
@PostMapping("/login")
public R login(String username, String password, HttpServletRequest req) {
YonghuEntity user = userService.selectOne(
new EntityWrapper<YonghuEntity>().eq("yonghuzhanghao", username)
);
if (user == null || !user.getMima().equals(password)) {
return R.error("Invalid credentials");
}
String token = tokenService.generateToken(user.getId(), username, "yonghu", "user");
return R.ok().put("token", token);
}
@PostMapping("/register")
public R register(@RequestBody YonghuEntity user) {
YonghuEntity existing = userService.selectOne(
new EntityWrapper<YonghuEntity>().eq("yonghuzhanghao", user.getYonghuzhanghao())
);
if (existing != null) {
return R.error("Username already exists");
}
user.setId(System.currentTimeMillis());
userService.insert(user);
return R.ok();
}
@GetMapping("/session")
public R getCurrentUser(HttpServletRequest req) {
Long userId = (Long) req.getSession().getAttribute("userId");
if (userId == null) return R.error("Not logged in");
YonghuEntity user = userService.selectById(userId);
return R.ok().put("data", user);
}
@PostMapping("/resetPass")
public R resetPassword(String username) {
YonghuEntity user = userService.selectOne(
new EntityWrapper<YonghuEntity>().eq("yonghuzhanghao", username)
);
if (user == null) return R.error("User not found");
user.setMima("123456");
userService.updateById(user);
return R.ok("Password reset to 123456");
}
@GetMapping("/list")
public R list(@RequestParam Map<String, Object> params, YonghuEntity condition) {
EntityWrapper<YonghuEntity> wrapper = new EntityWrapper<>();
// Apply filters like equality or partial match based on params
wrapper.like(StringUtils.isNotBlank(condition.getYonghuzhanghao()), "yonghuzhanghao", condition.getYonghuzhanghao());
// Pagination handled by service layer
Object pageData = userService.queryPage(params, wrapper);
return R.ok().put("data", pageData);
}
@PostMapping("/save")
public R save(@RequestBody YonghuEntity user) {
if (userService.existsByUsername(user.getYonghuzhanghao())) {
return R.error("Username already taken");
}
user.setId(System.currentTimeMillis());
userService.insert(user);
return R.ok();
}
@PostMapping("/update")
public R update(@RequestBody YonghuEntity user) {
if (userService.existsByUsernameExcludingId(user.getYonghuzhanghao(), user.getId())) {
return R.error("Username already in use");
}
userService.updateById(user);
return R.ok();
}
@PostMapping("/delete")
public R delete(@RequestBody List<Long> ids) {
userService.deleteBatchIds(ids);
return R.ok();
}
}
System testing follows black-box methodology, validating functionality against requirements through test cases covering login, registration, data retrieval, and error handling. Scenarios include valid/invalid inputs, boundary values, and role-based acess checks. The goal is to ensure the application behaves as expected from an end-user perspective, with all features operating correctly and securely before deployment.