controller类:
package com.rabbit.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.rabbit.hello.HelloSender1;
@RestController
@RequestMapping("/rabbit")
public class RabbitTest {
@Autowired
private HelloSender1 helloSender1;
@PostMapping("/hello")
public void hello() {
helloSender1.send();
}
}
结果通过地址栏访问hello方法报不支持Get访问,原来地址栏输入链接默认都是Get方式,将@PostMapping改为@RequestMapping就可以了 版权声明:本文为qingmengwuhen1原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。