mardi 24 janvier 2017

Pass value to controller in Spring MVC, what is the difference?

When I read some codes written with Spring MVC in an old project, I notice that the author using two similar method to pass value to controller as follows:

    @RequestMapping(value="/print")
    public String PrintInfo(@RequestParam("name") String name,@RequestParam("age") int age) {
.......
}

Or

    @RequestMapping(value="/print")
    public String PrintInfo(String name,int age) {
.......
}

Both them work well. The difference is whether it use the @RequestParam.

So what's the main difference between them? Which one is better, and why?




Aucun commentaire:

Enregistrer un commentaire