java 将后台实体类通过json格式传给前台

后台

import net.sf.json.JSONArray;


try {
			JSONObject result = new JSONObject();
			// 实体类
            Arr0302Entity arr0302Entity = new Arr0302Entity();
			JSONArray array=JSONArray.fromObject(arr0302Entity);
			result.put("arr0302Entity", array);
			response.setCharacterEncoding("UTF-8");
			response.setContentType("text/html;charset=UTF-8");
			PrintWriter pw = response.getWriter();
	        pw.print(result);
	        pw.close();
		} catch (IOException e) {
			e.printStackTrace();
		}

前台

$.ajax({
	            url : url,
	            type : "post",
	            async : false,// 同步执行
	            dataType : "json",
	            success : function(result) {
	            		// ***No
	            		$("#***_no").val(result.arr0302Entity[0].***_no);
	            		
	            	}
	            },
	        	error : function(errorMsg) {
	        		alert("请求数据失败");
	           }
	          });

参考文档:https://www.cnblogs.com/Revival-of-everything/p/10820809.html

猜你喜欢

转载自blog.csdn.net/c15162/article/details/116701984