gpt4 book ai didi

Spring MVC 发送 HTML 和 JSON

转载 作者:行者123 更新时间:2023-12-01 23:27:02 25 4
gpt4 key购买 nike

我需要在spring mvc中开发一个Web应用程序,它可以通过获取输入参数以html、json和xml响应客户端,我如何使用spring mvc设计这个,我知道使用@ResponseBody我可以获取xml或json响应,但是如何获取 html 响应,我需要为 html 和 json 提供不同的方法,还是可以使用相同的方法?

Example:
http://blip.tv/file/6213507?skin=json - Gives json o/p

http://blip.tv/file/6213507?skin=api - Gives xml o/p

http://blip.tv/file/6213507 - Gives html o/p

最佳答案

我发现了一个很好的例子,使用ContentNegotiatingViewResolver来做到这一点

关于Spring MVC 发送 HTML 和 JSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14136822/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com