22、3.2 Action

本文详细解释了MVC框架中Controller与Action的概念,Action作为请求的最小单位,必须是Controller中的public无参方法。文章通过代码示例展示了如何定义和使用Action,并介绍了getPara、getModel、setAttr及render等常用方法,帮助开发者深入理解Web请求处理的核心机制。

Controller 以及在其中定义的 public 无参方法称为一个 Action。Action 是请求的最小单位。

Action 方法必须在 Controller 中声明,该方法必须是 public 可见性且没有形参。

ublic class HelloController extends Controller {
public void index() { renderText(“此方法是一个action”);
}
public void test() { renderText(“此方法是一个action”);
}
}

以上代码中定义了两个 Action:HelloController.index()、HelloController.test()。在 Controller

中提供了 getPara、getModel 系列方法 setAttr 方法以及 render 系列方法供 Action 使用。