@RequestBody与@ResponseBody注解
@RequestBody,用于将请求体中的数据绑定到方法的形参中,该注解用在方法的形参上。
@ResponseBody,用于直接返回return对象,该注解用在方法上。
package com.ghl.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ghl.pojo.Student;
@Controller
public class StudentController {
@RequestMapping("/json")
@ResponseBody
public Student testJson(@RequestBody Student student)
{
//打印接收的JSON格式数据
System.out.println(student);
return student;
}
}
通过下述方法获取后台传入的jsonobject对象的值
var strJSON = "{name:'json name'}";//得到的JSON
var obj = eval( "(" + strJSON + ")" );//转换后的JSON对象
alert(obj.name);//json name
版权声明:本文为m0_52388979原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。