Issue
I'm using WebFlux for Web development. And I find 2 ways to express request mappings.
- Annotated Controllers: Like
@Controller
or@RestController
. RouterFunction
:RouterFunction
is used to route requests to aHandlerFunction
.
I find the second harder to use than the first and also I do not know the difference between them.
So I wanted to ask which performs better 2 or 1 ?
Thanks my friends!
Solution
Let me start with your last question
Is 2 better than 1, in performance?
No, there is no difference in the performance.
I find that 2 is harder to use than 1
That is absolutely based on individual preference. May be you are used to imperative style of programming. And hence you feel it easy to write(Trust me after a while you would feel the same with Router Functions as well)
Basically Router Functions are one step towards functional style of programming. Spring wanted users to have the flexibility to configure routes in functional style.
Apart from this there is no difference between Controllers and Router Functions.
Answered By - pvpkiran
Answer Checked By - Marie Seifert (JavaFixing Admin)