项目概述
本案例基于 Spring Boot 与 jQuery 构建前后端分离的图书管理系统,重点演示从接口设计到前端联调的完整流程。我们将实现用户登录验证及图书列表展示功能,并深入探讨开发中常见的请求方式差异问题。
核心接口设计
1. 数据模型定义
首先定义后端实体类 BookInfo,用于映射图书信息。注意字段命名需与实际业务保持一致。
@Data
public class BookInfo {
// 图书 ID
private Integer id;
// 书名
private String bookName;
// 作者
private String author;
// 数量
private Integer count;
// 定价
private BigDecimal price;
// 出版社
private String publish;
// 状态 0-不允许借阅 1-允许借阅
private Integer status;
private String statusCN;
// 创建时间
private Date createTime;
// 更新时间
private Date updateTime;
}
2. 登录接口实现
使用 UserController 处理用户认证逻辑,通过 Session 维持会话状态。
import jakarta.servlet.http.HttpSession;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RequestMapping("/user")
@RestController
public class UserController {
@RequestMapping("login")
public boolean {
(!StringUtils.hasLength(name) || !StringUtils.hasLength(password)) {
;
}
(.equals(name) && .equals(password)) {
session.setAttribute(, name);
;
}
;
}
}


