如何使用Json请求,来自其他应用程序,例如“ .Net”,我想将其使用到Java应用程序中。
如何在Spring MVC中与Controller一起使用。
谢谢 沙申克
答案 0 :(得分:0)
您基本上是在问控制器如何工作!控制器的工作是处理对其服务的任何(JSON或...)请求。 我建议您阅读一些有关spring MVC和控制器的文章,以了解其工作原理。
https://www.baeldung.com/building-a-restful-web-service-with-spring-and-java-based-configuration
https://www.in28minutes.com/spring-mvc-tutorial-for-beginners
答案 1 :(得分:0)
如果我能够理解您的问题,那么您正在询问如何将JsonRequest发布到RestController,为此,我附上了一个代码片段,希望对您有所帮助。
步骤1:创建该JSON请求的模型类。 步骤2:使用Controller方法标记@RequestBody注释,以在Method参数中获取该类型的对象。
@RequestMapping(value = "/getRequest", method = { RequestMethod.POST },
produces = {"application/json"})
public @ResponseBody Object getResponse(@RequestBody JsonRequest request) {
sysout("Json Body: "+request.toString());
}