首先要了解一下@RequestMapping注解。
@RequestMapping用於映射url到控制器類的一個特定處理程序方法。可用於方法或者類上面。也就是可以通過url找到對應的方法。
@RequestMapping有8個屬性。
value:指定請求的實際地址。
method:指定請求的method類型(GET,POST,PUT,DELETE)等。
consumes:指定處理請求的提交內容類型(Context-Type)。
produces:指定返回的內容類型,還可以設置返回值的字符編碼。
params:指定request中必須包含某些參數值,才讓該方法處理。
headers:指定request中必須包含某些指定的header值,才讓該方法處理請求。
@getMapping與@postMapping是組合注解。
@getMapping = @requestMapping(method = RequestMethod.GET)。
@postMapping = @requestMapping(method = RequestMethod.POST)。