spring mvc传json给前台报406解决方法


1.添加jackson-annotations-2.7.4.jar       jackson-core-2.7.4.jar        jackson-databind-2.7.4.jar

2.springmvc-servlet.xml配置

 
	
		
			
				text/html;charset=UTF-8
				
				application/json;charset=UTF-8
			
		
	

	
	
		
			
				
			
		
	

3.controller

	@RequestMapping("/selectAll")
	@ResponseBody
	public Map selectAll(){
		Map map=new HashMap<>();
		map.put("list", userService.selectAll());
		return map;
	}

4.js

$.ajax({
		 url : contextPath+'/user/selectAll.do',
		 datatype : "json",
		 type : "POST",
	         headers : {
			"Accept" : "application/json;; charset=utf-8",
			"Content-Type" : "application/json;; charset=utf-8"
		},
		async : true,
		beforeSend : this.beforeSend,
		success:function(result){
		    $(result.list).each(function(){
		    	 var obj=eval(this);
			     alert(obj.name);
		    	 });
		    }
	});


你可能感兴趣的:(springmvc)