1:java代码:
@Controller  
@RequestMapping("/json")  
public class JsonTest  
{  
   
    @RequestMapping(value="/user", method = RequestMethod.GET)  
    public @ResponseBody  User  getJson()
    {  

    	User user = new User();
    	user.setPwd("pdd");
    	user.setUsername("name");
        return user;  
    }  
    @RequestMapping(value = "/insert",method = RequestMethod.POST)
    public void getJson(@RequestBody User user)
    {
    	System.out.println(user.getUsername());
    }

} 
class User
{
	private String username;
	private String pwd;
	public String getUsername() {
		return username;
	}
	public void setUsername(String username) {
		this.username = username;
	}
	public String getPwd() {
		return pwd;
	}
	public void setPwd(String pwd) {
		this.pwd = pwd;
	}
	
}
2:Ajax

var user = {};
	user.username = "test";
	user.pwd = "pwd";
	var json = JSON.stringify(liasion);
	$.ajax({
		url:'json/insert',
		type:'POST',
		data : json,
		dataType : 'json',
		contentType : 'application/json;charset=UTF-8',
		success:function(obj)
		{
			
		}
	})


相关文章:

  • 2022-02-09
  • 2021-10-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-12
  • 2021-11-05
  • 2021-10-14
猜你喜欢
  • 2021-05-04
  • 2021-09-10
  • 2021-11-05
  • 2021-11-05
  • 2021-11-05
  • 2022-01-17
  • 2022-02-09
相关资源
相似解决方案