今天看了下@RequestMapping源码,发现它的value值是数组,以前既然都没有注意到这一点。试了一下同一方法可以配置多个地址。
@SpringBootApplication
@RestController
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
@RequestMapping(value = {"/t1","t2","t3"})
public void test() {
System.out.println("t1");
}
}
curl "http://localhost:8080/t1"
curl "http://localhost:8080/t2"
curl "http://localhost:8080/t3"