SmartWeb
SmartWeb 是基于 Rain 的 JVM Web 后端框架。Rain 提供依赖注入、配置、事件和应用生命周期,SmartWeb 在此之上提供 Controller、路由、参数绑定和 HTTP 服务器抽象。
写法上它接近 Spring MVC:用注解声明 Controller 和 Action,方法参数自动绑定,返回值自动序列化为 JSON。
kotlin
@WebController
@Path("users")
class UserController {
@GetAction("{id}")
fun getUser(id: Long) = mapOf("id" to id)
}功能概览
@WebController声明控制器,@GetAction、@PostAction等注解声明路由和请求方法- 参数可来自路径变量、查询参数、JSON 请求体、Session、Cookie 和 Action 上下文
- 文件上传、文件下载和自定义
Render @Before、@After、@Catch过程链,以及把业务注解编译为过程的ProcessProvider@NewWs注册 WebSocket- 多个命名服务器,服务器实现可替换
- 服务器启停、路由未命中等事件
模块
| Artifact | 作用 |
|---|---|
com.IceCreamQAQ.SmartWeb:SmartWeb | Controller、路由、参数绑定与服务器抽象 |
com.IceCreamQAQ.SmartWeb.Server:SmartHTTP | 基于 smart-http-server 的服务器实现 |
com.IceCreamQAQ.SmartWeb.Server:Undertow | 基于 Undertow 的服务器实现,功能不完整 |
com.IceCreamQAQ.SmartWeb.Temple:Rythm | Rythm 模板引擎集成,当前不可用 |
当前版本为 1.0.0-DEV15,目标 JVM 8。SmartWeb 仍处于开发阶段,API 和依赖版本可能变化。两个服务器实现的差异见服务器与配置。