Java记账系统项目实战 | Spring Boot + MyBatis Plus + Layui 前后端整合开发

本项目为一款基于 Spring Boot 构建的简洁实用型 Java 记账系统,集成了 MyBatis Plus、Druid 数据源、Thymeleaf 模板引擎及 Layui 前端组件,实现了从账单录入、查询、统计到基础用户登录的完整功能流程。


🎯 页面预览截图(可选)

📌 登录页

📌 账单列表页

📌 添加账单弹窗

📌 数据可视化列表展示

📌 项目功能一览

  • 用户登录 + 验证码校验

  • 账单录入(含分类、时间、金额、备注)

  • 账单列表展示、查询筛选、分页加载

  • 分类信息缓存机制(AOP 实现)

  • 基于 MyBatis Plus 的代码生成与数据操作

  • 简洁前端界面(Layui + Thymeleaf)


🏗 技术选型

技术/工具 用途
Spring Boot 项目主框架
MyBatis Plus 持久层框架,简化SQL操作
Druid 数据源连接池及监控
Thymeleaf 页面模板引擎
Layui 前端组件库,快速构建表单和表格
Lombok 简化实体类代码
Hutool 工具类库
AOP 缓存实现(账单类型)

🧩 数据库配置(application.yml)

XML 复制代码
spring: 
    datasource:     
        druid:     
            driver-class-name: com.mysql.cj.jdbc.Driver 
            url:jdbc:mysql://127.0.0.1:3306/bills?useUnicode=true&characterEncoding=utf8&useSSL=true&serverTimezone=UTC 
            username: root 
            password: 123456

🔧 Maven 依赖配置(pom.xml)

主要依赖包括:

  • spring-boot-starter-web

  • mybatis-plus-boot-starter

  • druid-spring-boot-starter

  • thymeleaf

  • log4j

  • hutool-all

  • lombok

片段如下:

XML 复制代码
<dependency>
  <groupId>com.baomidou</groupId>
  <artifactId>mybatis-plus-boot-starter</artifactId>
</dependency>
<dependency>
  <groupId>com.alibaba</groupId>
  <artifactId>druid-spring-boot-starter</artifactId>
</dependency>

🧑‍💻 登录功能实现(含验证码)

使用 LoginController 实现用户登录:

java 复制代码
@RequestMapping("login")
@ResponseBody
public ResultObj login(String loginname,String pwd,String code,HttpSession session) {
    Object codeSession = session.getAttribute("code");
    if(code != null && code.equals(codeSession)) {
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("loginname", loginname);
        queryWrapper.eq("pwd", pwd);
        User user = userService.getOne(queryWrapper);
        return (user != null) ? new ResultObj(200, "登录成功") : new ResultObj(-1, "用户名或密码错误");
    } else {
        return new ResultObj(-1, "验证码错误");
    }
}

验证码采用 Hutool 提供的 CaptchaUtil 生成:

java 复制代码
CircleCaptcha captcha = CaptchaUtil.createCircleCaptcha(116, 36, 4, 5);
session.setAttribute("code", captcha.getCode());

📋 账单管理模块

💼 账单列表展示(list.html)

通过 Layui 的 table 组件实现分页数据加载:

bash 复制代码
table.render({
  elem: '#billTable',
  url: '/bills/loadAllBills',
  page: true,
  cols: [[
    {field:'title', title:'账单标题'},
    {field:'billtime', title:'记账时间'},
    {field:'typeName', title:'类型名称'},
    {field:'price', title:'账单金额'},
    {field:'remark', title:'账单备注'}
  ]]
});

📝 添加账单功能

通过点击按钮触发 Layui 弹出层,动态加载账单类型,并提交至后台:

bash 复制代码
$("#doAdd").on("click", function() {
  // 弹出添加表单
  layer.open({
    type: 1,
    content: $("#addBillDiv"),
    area: ['800px', '600px']
  });
});

⚡ 缓存优化:AOP实现账单类型缓存

通过 Spring AOP 实现简单的本地缓存机制:

java 复制代码
@Around(value="pc()")
public Object cacheBillType(ProceedingJoinPoint point) throws Throwable {
    Integer typeId = (Integer) point.getArgs()[0];
    Object cached = cache.get(BILL_TYPE_CACHE_PREFIX + typeId);
    if (cached != null) return cached;
    Billtype res = (Billtype) point.proceed();
    cache.put(BILL_TYPE_CACHE_PREFIX + res.getId(), res);
    return res;
}

🧠 项目适用场景

  • Java Web 实战练手项目

  • 中小企业财务系统雏形

  • 个人理财系统学习样例

  • 系统架构+前后端集成完整参考


✅ 结语

本项目功能完整,界面清爽,适合用于快速搭建 Web 账务管理系统的参考案例。如果你正在学习 Spring Boot、MyBatis Plus、Layui 等技术,这将是一个非常不错的实战模板!

💬 如需源码、演示效果或部署指导,欢迎评论交流!

相关推荐
Mr_pyx26 分钟前
【LeetHOT100】二叉树的中序遍历——Java多解法详解
java·开发语言·深度优先
jay神37 分钟前
基于SpringBoot的宠物生命周期信息管理系统
java·数据库·spring boot·后端·web开发·宠物·管理系统
万亿少女的梦1681 小时前
基于SpringBoot的在线考试管理系统设计与实现
java·spring boot·后端
一勺菠萝丶1 小时前
如何在 Linux 服务器上使用 Speedtest 官方 CLI 测试带宽(小白教程)
java·服务器·前端
范什么特西2 小时前
第一个Mybatis
java·开发语言·mybatis
下次再写2 小时前
【Redis实战】深入理解Redis缓存策略:从原理到Spring Boot实践
java·spring boot·redis·缓存穿透·缓存击穿·分布式缓存·缓存策略
超梦dasgg2 小时前
智慧充电系统计费定价服务Java 实现
java·开发语言·spring·微服务
敲敲千反田2 小时前
ThreadLocal和CompletableFuture
java·网络·jvm
码云数智-园园2 小时前
Spring循环依赖:三级缓存到底解决了什么,没解决什么?
java·后端·spring
龙亘川2 小时前
城市更新×智慧治理:老旧小区改造中的数字化创新实践
java·大数据·人工智能·机器学习·智慧城市