图书管理系统实战
前端资源准备
开发前需准备好前端静态资源,包括 HTML 页面与 jQuery 库文件。本示例聚焦于后端接口设计与前后端联调逻辑。
接口设计与后端实现
数据模型定义
首先定义图书实体类 BookInfo,使用 Lombok 简化代码结构:
@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;
}
用户登录接口
在 UserController 中实现简单的登录验证。注意:实际生产环境应对接数据库并加密密码,此处仅为演示逻辑。
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);
;
}
;
}
}


