开发者

Simplest way to pass a Serialized object from client to Spring controller and get back serialized object response?

开发者 https://www.devze.com 2023-03-06 08:20 出处:网络
I have been reading a lot of tutorials about this, I have been able to use HttpClient to make a POST to spring and get the response back but it was just using a string being passed in. I would like to

I have been reading a lot of tutorials about this, I have been able to use HttpClient to make a POST to spring and get the response back but it was just using a string being passed in. I would like to, for example, serialize an object such as Map <String, String> testMap = new HashMap <String, 开发者_如何学PythonString> () and then pass this into a Spring controller, from a client. Then I would just like to, for simplicity's sake, return this same object to the client from Spring. I don't care if it uses HttpClient or something else, I just want to figure a way to make this work.

I have tried looking at different approaches but I can't seem to piece it together. Could anyone point me towards a resource that outlines a simple way to do this. I would greatly appreciate any advice, thanks


I don't think SpringMVC is really written with passing objects back and forth in mind. It is designed for serving up dynamic web content, not so much for communication with an intelligent client (a.k.a, not a web browser). There are other approaches such as JAX-RS and JAX-WS which are better at that.

That being said, there could still be a way to do what you're trying to do. If you're trying to pass multiple fields from the client to the server you could use a form and an AbstractFormController.

If you want to populate your view with multiple data objects from your model then you can look at the ModelAndView and the ModelMap.

Also, your view could use JAXB or Jackson directly to serialize your data objects as XML/JSON and return it that way but then you'd be manually doing steps that are automated in other frameworks.

0

精彩评论

暂无评论...
验证码 换一张
取 消