Interactive SSM12-Ajax and the front desk json

1. To achieve lower ssm Ajax and the front desk json interaction, first of all to support ssm way to json data sent in response to reception

  1.1jar support package (using maven)

     <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-core</artifactId>
            <version>2.9.5</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.9.5</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-annotations</artifactId>
            <version>2.9.5</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.module</groupId>
            <artifactId>jackson-module-jaxb-annotations</artifactId>
            <version>2.9.5</version>
        </dependency>

 

  Let ssm 1.2 framework supports json

<bean id="jsonConverter" class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
        <property name="supportedMediaTypes">
            <list>
                <value>application/json;charset=UTF-8</value>
            </list>
        </property>
    </bean>

 

  

  1.3 in the way of response to add comments @ResponseBody

@ResponseBody

 

 

2. The common mode request ajax

  2.1 stand-alone triggered when an element

$("button").click(function(){
    $.ajax({
        type:"get
        url:
"demo_test.txt",

        success:function(result){    $("#div1").html(result);    }
  }); });

 

 

        2.2 Method arranged

function check() {
            $.ajax({
                type: "get",
                dataType: "json",
                url: "/history",
                success: function (data) {

                }
            });

 

 

3.java turn json support rules

json数据时由键值对构成的

  var p = {"name":"zhangsan","age":123}

  *键用引号也可以不用,引起来

  *值的取值

    1.数字:直接写就可以了不用引号

    2.字符串:引号引起来

    3.逻辑值:ture或false

    4.数组:在[]方括号中  {“persion”:[{"白人"},{"黑人"},{“黄人”}]}

    5.对象:在{}花括号中  {“Country”:{"city":"南京",...},{...}}

 

 

 

 

 

 

 

 

 

 

Guess you like

Origin www.cnblogs.com/asndxj/p/11596215.html