Skip to content

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:SmartWebController、路由、参数绑定与服务器抽象
com.IceCreamQAQ.SmartWeb.Server:SmartHTTP基于 smart-http-server 的服务器实现
com.IceCreamQAQ.SmartWeb.Server:Undertow基于 Undertow 的服务器实现,功能不完整
com.IceCreamQAQ.SmartWeb.Temple:RythmRythm 模板引擎集成,当前不可用

当前版本为 1.0.0-DEV15,目标 JVM 8。SmartWeb 仍处于开发阶段,API 和依赖版本可能变化。两个服务器实现的差异见服务器与配置。

阅读路线 ​

  1. 快速开始
  2. 路由与控制器
  3. 请求与参数绑定
  4. 响应与渲染
  5. Before / After / Catch 过程链
  6. WebSocket
  7. 服务器与配置
  8. 扩展开发
  9. 与 Spring MVC 对照

基于 Apache License 2.0 发布