国产片侵犯亲女视频播放_亚洲精品二区_在线免费国产视频_欧美精品一区二区三区在线_少妇久久久_在线观看av不卡

服務器之家:專注于服務器技術及軟件下載分享
分類導航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術|正則表達式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

服務器之家 - 編程語言 - Java教程 - Springmvc 4.x利用@ResponseBody返回Json數據的方法

Springmvc 4.x利用@ResponseBody返回Json數據的方法

2021-04-22 11:07涵涵YH Java教程

這篇文章主要介紹了Springmvc 4.x利用@ResponseBody返回Json數據的方法,小編覺得挺不錯的,現在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧

下面是官方文檔對于@responsebody注解的解釋:

?
1
2
3
4
5
6
7
8
9
10
11
12
mapping the response body with the @responsebody annotation
 
the @responsebody annotation 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(path = "/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.

@resopnsebody注解能夠 直接把 控制器返回變量(string)直接 返回給瀏覽器,也可以通過配置 后,把 對象 序列化成json數據返回給瀏覽器!如果為 null 就會返回空白。

怎么配置呢 ?需要配置messageconverter:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<bean 
    class="org.springframework.web.servlet.mvc.annotation.annotationmethodhandleradapter"
    <property name="messageconverters"
      <list> 
        <ref bean="mappingjackson2httpmessageconverter" /> 
      </list> 
    </property> 
  </bean> 
  <bean id="mappingjackson2httpmessageconverter"
    class="org.springframework.http.converter.json.mappingjackson2httpmessageconverter"
    <property name="supportedmediatypes"
      <list> 
        <value>text/html;charset=utf-8</value> 
        <value>text/json;charset=utf-8</value> 
        <value>application/json;charset=utf-8</value> 
      </list> 
    </property> 
  </bean>

下面貼出在官方文檔中的位置:

Springmvc 4.x利用@ResponseBody返回Json數據的方法

這個需要jackson jar包支持,需要 jackson-annotations,jackson-core,jackson-databind三個包,:

Springmvc 4.x利用@ResponseBody返回Json數據的方法

控制器代碼:

?
1
2
3
4
5
6
7
@requestmapping("house/classmanager/addbyajax")
  @responsebody
  public hanblog_class classmanager_addbyajax(httpservletrequest request){
    if(request.getsession().getattribute("hanblog_uid")==null) return null;
    hanblog_class objclass=new hanblog_class();
    return objclass;
  }

jquery代碼:

?
1
2
3
4
5
6
7
8
9
//|增加
    $("#hanblog_add_btn").click(function(){
      var classname=$("#add_input_name").val();
      var classintroduction=$("#add_input_introduction").val();
      alert("分類名稱:"+classname+"分類介紹:"+classintroduction);
      $.get("<c:url value="/house/classmanager/addbyajax.do" />",function(result){
        alert(result);
      });
    });

運行返回例子:

Springmvc 4.x利用@ResponseBody返回Json數據的方法

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持服務器之家。

原文鏈接:https://blog.csdn.net/u012997311/article/details/51982461

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 国色天香成人网 | 国产精品一区二区三区免费 | 亚洲精品成人18久久久久 | 日本视频免费 | 日本a视频 | 日韩高清一区二区 | 精品亚洲一 | 日本三级视频在线观看 | 精品日韩一区二区 | 精品国产乱码久久久久久丨区2区 | 蜜桃视频网站在线观看 | 在线观看成人 | 成人免费在线观看网址 | 在线免费观看av电影 | 亚洲一区二区三区四区五区午夜 | 久久中国精品 | 亚洲精品字幕 | 国产精品极品美女在线观看免费 | 激情久久网 | 羞羞羞网站 | 欧美一级一区 | 日韩a电影| 国产免费黄色 | 在线精品亚洲欧美日韩国产 | 一级片欧美 | 日本不卡免费新一二三区 | 日韩国产欧美视频 | 午夜寂寞少妇aaa片毛片 | 一本大的之伊人 | 中文字幕日韩欧美 | 亚洲性网 | 国产精品不卡视频 | 极品一区| 香蕉av777xxx色综合一区 | 日韩成人在线视频 | 成人免费视频网站在线观看 | 国产玖玖视频 | 免费成人高清在线视频 | 午夜精品久久久久久久久 | 在线观看国产 | 寡妇少妇高潮免费看蜜臀a 午夜免费电影 |