Introduce composed annotations for @RequestMapping
This commit introduces the following common composed annotations for @RequestMapping in Spring MVC and Spring MVC REST. - @GetMapping - @PostMapping - @PutMapping - @DeleteMapping - @PatchMapping Issue: SPR-13992
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -23,6 +23,7 @@ import java.util.concurrent.Callable;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -36,7 +37,7 @@ import org.springframework.test.context.web.WebAppConfiguration;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.MvcResult;
|
||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
import org.springframework.web.context.request.async.CallableProcessingInterceptor;
|
||||
@@ -55,6 +56,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||
* Tests with Java configuration.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
* @author Sam Brannen
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@WebAppConfiguration
|
||||
@@ -123,7 +125,7 @@ public class AsyncControllerJavaConfigTests {
|
||||
@RestController
|
||||
static class AsyncController {
|
||||
|
||||
@RequestMapping(path = "/callable")
|
||||
@GetMapping("/callable")
|
||||
public Callable<Map<String, String>> getCallable() {
|
||||
return () -> Collections.singletonMap("key", "value");
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,25 +16,24 @@
|
||||
|
||||
package org.springframework.test.web.servlet.samples.context;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.test.web.Person;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@Controller
|
||||
@RestController
|
||||
@RequestMapping("/person")
|
||||
public class PersonController {
|
||||
|
||||
private final PersonDao personDao;
|
||||
|
||||
|
||||
public PersonController(PersonDao personDao) {
|
||||
PersonController(PersonDao personDao) {
|
||||
this.personDao = personDao;
|
||||
}
|
||||
|
||||
@RequestMapping(value="/person/{id}", method=RequestMethod.GET)
|
||||
@ResponseBody
|
||||
@GetMapping("/{id}")
|
||||
public Person getPerson(@PathVariable long id) {
|
||||
return this.personDao.getPerson(id);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user