我有这个职业DemoController
。在这个类中,我想随REST请求一起发送消息。如何将消息与RESTful请求一起传递?
我该如何发送?假设M发送http://localhost:8080/sendmessage...
如何随此请求一起发送消息?
@RestController
@EnableAutoConfiguration
public class DemoController {
@Autowired
DemoPublisher demopublisher;
@Autowired
DemoConsumer democonsumer;
@RequestMapping(value="/sendmessage", method= {RequestMethod.POST})
@ResponseBody
public String messageSenderController(@RequestParam String message, Model model){
try {
demopublisher.demoPublishMessage(message);
} catch (JMSException e) {
e.printStackTrace();
}
return message;
}
}
您可以使用QueryParam,PathVariable或RequestBody将数据传递到其余控制器。你希望这个消息成为url的一部分吗? –
是在我想要的网址 –
因为我使用Spring启动应用程序,所以这是我的主要类从这里我如何发送消息到控制器与休息请求。 public static void main(String [] args){ \t \t SpringApplication.run(MessagingApplication.class,args); \t} –