欢迎访问 生活随笔!

凯发k8官方网

当前位置: 凯发k8官方网 > 前端技术 > javascript >内容正文

javascript

【spring reference】@responsebody注解 -凯发k8官方网

发布时间:2025/1/21 javascript 30 豆豆
凯发k8官方网 收集整理的这篇文章主要介绍了 【spring reference】@responsebody注解 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

为什么80%的码农都做不了架构师?>>>   

spring reference写到:

mapping the response body with the @responsebody annotation

the @responsebodyannotation is similar to @requestbody. this annotation can be put on a method and indicates that the return type should be written straight to the http response body (and not placed in a model, or interpreted as a view name).
for example:
@requestmapping(value = "/something", method = requestmethod.put)
@responsebody
public string helloworld() {
    return "hello world";
}
 
the above example will result in the text hello world  being written to the http response stream. as with @requestbody, spring converts the returned object to a response body by using an httpmessageconverter. for more information on these converters, see the previous section and message converters.
jast领会到:


使用@responsebody注解映射响应体
@responsebody注解和@requestbody注解类似。这个注解能使用在方法上,用来指明该方法的返回类型将直接作为响应给http请求(不会换成model,或解析为视图的名字)

举个例子:
@requestmapping(value = "/something", method = requestmethod.put)
@responsebody
public string helloworld() {
    return "hello world";
}
这上面的例子将以text/html形式响应http请求。和@requestbody一样,spring使用httpmessageconverter来将方法的返回值进行类型转换的。对于不同的返回值spring会转化成不同的 类型。







转载于:https://my.oschina.net/jast90/blog/286513

总结

以上是凯发k8官方网为你收集整理的【spring reference】@responsebody注解的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得凯发k8官方网网站内容还不错,欢迎将凯发k8官方网推荐给好友。

网站地图