Solon v2.7.5

六、Action 结构图及两种注解处理

</> markdown

1、相关接口

接口说明
-name()->String名字
-mapping()->Mapping映射
-method()->MethodWrap方法包装器
-controller()->BeanWrap控制类包装器
-produces()->String生产内容(主要用于文档生成)
-consumes()->String消费内容 (主要用于文档生成)

2、获取方式

Action action = ctx.action(); //可能为 null

3、两种重要的注解处理

Action 本质上是 Handler 和 Class Method 的结合。所以它支持两种风格的注解和拦截处理:

a) Handler 的责任链式拦截处理

具体参考: 《@Before、@After 用法说明》 。其中 @Before 在 Method 参数转换之前执行(一般用做提前校验);@After 则在 Method 执行并输出后执行(不管是否异常都会执行,一般做些补充记录)。例如:

@Before(WhitelistHandler.class)
@Target({ElementType.METHOD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
public @interface Whitelist { }

@Controller
public class DemoController{
    @Whitelist
    @Mapping("user/del")
    public void delUser(..){  }
}

b) Class Method 的包围式拦截处理

具体参考:《@Around 使用说明》《切面与环绕拦截》