what is the dif between requestMapping on controller and method

A @RequestMapping on the class level is not required. Without it, all paths are simply absolute, and not relative.

see 15.3.2 Mapping requests with @RequestMapping

This means if you specify the classlevel annotations, the url shall be relative, so for register it shall be /user/register(URL to Handler mapping) and likewise.


As described here you can also use Type level mapping and relative path mappings on method level to be dry and don't duplicate root at every methods.

@Controller
@RequestMapping("/employee/*")
public class Employee {

    @RequestMapping("add")
    public ModelAndView add(
            @RequestParam(value = "firstName") String firstName,
            @RequestParam(value = "surName") String surName) {
        //....
    }

    @RequestMapping(value={"remove","delete"})
    public ModelAndView delete(
        //....
    }   
}

Spring doc: At the method level, relative paths (e.g. "edit.do") are supported within the primary mapping expressed at the type level.