New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

一个Action类只能实现一个路由? #12

Closed
zzzzbw opened this Issue Oct 8, 2018 · 6 comments

Comments

Projects
None yet
3 participants
@zzzzbw

zzzzbw commented Oct 8, 2018

Is your feature request related to a problem? Please describe.
Action类是通过实现WorkAction接口的execute()方法来实现路由的,这样一个类只能实现一个路由,实际使用起来未必会有点麻烦吧

Describe the solution you'd like
如果能够像spring mvc那样一个controller下可以有多个RequestMapping就比较好吧。

Describe alternatives you've considered
Action类不用实现WorkAction接口,直接扫描所有被@CicadaAction注解的类,然后再反射获取这个类中被@CicadaExcute注解的方法(我看到有@CicadaExcute这个注解,但没有被使用,是否是准备用于这方面的?),再反射调用这个方法。

不过这样的话就是比较难约束用户对于被@CicadaExcute注解的方法传入的参数,我想到有两种方式约束:

  • 约束必须传入且只能传入CicadaContextParam,否则就抛出异常
  • 可以任意传入参数,如果检查到有CicadaContextParam就在invoke的时候传进去,如果没有就不传,如果有其他参数就传null值。
@crossoverJie

This comment has been minimized.

Member

crossoverJie commented Oct 8, 2018

@zzzzbw

哈哈 是的。

@CicadaExcute 是之前预留的。

在上篇文章中有写到后续会有这个更新。

@zzzzbw

This comment has been minimized.

zzzzbw commented Oct 8, 2018

@crossoverJie
哈哈,竟然被我提前说出来了。
不过我还是比较想了解对于方法传参你准备怎么处理的?
之前我也写了一个mvc框架,感觉上面提到的两个方式都不是很好。

@crossoverJie

This comment has been minimized.

Member

crossoverJie commented Oct 8, 2018

@zzzzbw

现在已经有一个大概的思路。其中的参数传递可以是自定义的 pojo,比如:

    @CicadaExcute("get")
    public void get(CicadaContext context,User user){
        context.json(user);
    }

甚至 CicadaContext context 也可以不要,毕竟这个上下文可以在一次请求的任意一个地方获取。

同时也可以在参数中使用 Cicada 预设的 CicadaRequest、CicadaResponse、CicadaCookie 等。

只需要在路由过程中将数据反射写入具体的参数即可。

@zzzzbw

This comment has been minimized.

zzzzbw commented Oct 9, 2018

谢谢你的解答,期待其实现

@cjqCN

This comment has been minimized.

Member

cjqCN commented Oct 9, 2018

@crossoverJie
自定义pojo的话,我觉得可以通过不同的注解到path、header、param或者content取值

@crossoverJie

This comment has been minimized.

Member

crossoverJie commented Oct 9, 2018

@cjqCN

嗯,实现都是一样的。只是注解可读性更强。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment