# LazyCat
**Repository Path**: leavingme/lazycat
## Basic Information
- **Project Name**: LazyCat
- **Description**: 极简、 IOC、AOP、WEB、启动快、高性能、好维护,核心代码仅 500 KB。
- **Primary Language**: Java
- **License**: MulanPSL-2.0
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 31
- **Forks**: 0
- **Created**: 2025-07-01
- **Last Updated**: 2026-03-19
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# 懒王猫(Lazycat)
## 介绍
不是为了超越谁, 只想做更好的自己。
Lazycat (懒王猫) 是一个基于 Java 的轻量级 Web 框架,支持 IOC、AOP、事务管理、数据库操作、HTTP 服务、静态资源服务等功能。
代码轻量、简单、启动快、高性能、好维护, 程序打包15M以内, 却拥有完整的Web功能。
此外,本项目还包含了一个完整的 **内网穿透 (Lazycat Netpipe)** 解决方案。
## 软件架构
Lazycat 采用模块化设计,核心模块包括:
**核心基础模块:**
- **lazycat-aop**:基于 AOP 的拦截器支持,提供方法级别的切面编程能力。
- **lazycat-core**:框架核心,提供基础配置、插件系统、事件监听、异常处理等。
- **lazycat-utility**:通用工具类模块,包含 IO、字符串、反射、资源扫描等实用工具。
**数据处理模块:**
- **lazycat-datasource**:数据源模块,集成 HikariCP 数据库连接池。
- **lazycat-jdbc**:JDBC 操作封装,提供数据库访问模板和工具类。
- **lazycat-mybatisflex**:集成 MyBatis-Flex ORM 框架,简化数据库操作。
- **lazycat-tx**:事务管理模块,支持声明式事务和编程式事务。
**Web 服务模块:**
- **lazycat-jdkhttp**:HTTP 服务模块,基于 JDK 自带的 `HttpServer` 提供 Web 服务。
- **lazycat-web**:WEB 模块,提供路由定义、控制器支持、静态资源管理等功能。
**应用模块:**
- **lazycat-netpipe**:轻量级内网穿透解决方案,包含服务端、客户端及可视化桌面管理端。
## 安装教程
1. **Maven 依赖**
在 `pom.xml` 中添加 Lazycat 的依赖。例如:
```xml
xyz.lwm
lazycat-parent
1.0-SNAPSHOT
pom
import
xyz.lwm
lazycat-web
....
```
根据需要添加其他模块,如 `lazycat-aop`, `lazycat-jdbc`, `lazycat-jdkhttp` 等。
2. **配置文件**
在 `resources` 目录下创建 `application.yml` 或 `application.properties` 文件,配置数据库连接、Web 端口等信息。
3. **启动应用**
创建主类并调用 `Application.start()` 启动框架:
```java
@MapperScan("com.example.mapper")
public class App {
public static void main(String[] args) {
Application.start();
}
}
```
## 使用说明
### 1. 路由定义
使用 `get`, `post`, `put`, `delete` 等注解或 `Router` 原始用法定义路由:
```java
@Controller("example")
public class ExampleController implements Controllable {
@Inject
private ExampleService exampleService;
@Override
public void control(Router router) {
// 原始用法定义路由
router.get("teachers", ctx -> {
List teachers = exampleService.getTeacherList();
ctx.json(R.ok(teachers));
});
router.get("teachers/{teacherId}", ctx -> {
String teacherId = ctx.req().getPathParam("teacherId");
Long id = Convert.to(teacherId, Long.class);
Teacher teacher = exampleService.getTeacherById(id);
ctx.json(R.ok(teacher));
});
// 前置拦截器
router.before("example/students/**", ctx -> {
System.out.println("before students");
});
}
// 注解定义路由
@Get("students")
public R> getStudents() {
return R.ok(exampleService.getStudentList());
}
@Get("students/{id}")
public R getStudentById(@PathParam("id") Long id) {
return R.ok(exampleService.getStudentById(id));
}
@Post("students")
public R> getStudentsBy(@Form StudentParam param) {
return R.ok(exampleService.getStudentsBy(param));
}
}
```
### 2. AOP 切面
通过实现 `Aspect` 接口定义切面逻辑,并使用 `@Order` 控制执行顺序。
### 3. 数据库操作
使用 `JdbcTemplate` 进行数据库操作:
```java
@Autowired
private JdbcTemplate jdbcTemplate;
List