zoukankan      html  css  js  c++  java
  • SpringMVC接受返回JSON数组

    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)
    		{
    			
    		}
    	})


  • 相关阅读:
    淘宝网六个质量属性场景
    架构漫谈阅读笔记2
    poj 3304
    poj 2318
    bzoj 4008
    任意模数NTT
    CF623E
    CF712E
    bzoj 1925
    bzoj 4710
  • 原文地址:https://www.cnblogs.com/MedivhQ/p/4074924.html
Copyright © 2011-2022 走看看