通过jquery直接从数据库获取显示在html页面

1.SERVICE
public MonthBusiness getThisMonthBusinessAll(String agentID){
Map<String, Object> paramMap = new HashMap<String, Object>();
String sqlStr="select * from table(PKG_SFA_THISMONTHBUSINESSALL.getThisMonthBusinessAll(:I_AGENTID))";
paramMap.put("I_AGENTID", CommonUtil.jugeAndFixNull(agentID));
List<MonthBusiness> mothbusiness = new ArrayList<MonthBusiness>();
mothbusiness = jdbcTemplate.query(sqlStr, paramMap, new BeanPropertyRowMapper<MonthBusiness>(MonthBusiness.class));
return mothbusiness.get(0);
}
------------------------------------------------------------------
2.CONTROLLER
MonthBusiness business = newsService.getThisMonthBusinessAll(user
.getUserAgentId());// 本月所有业务数

StringBuffer result = new StringBuffer();

result.append("{");
result.append("THISMONTHUNDERWRITEEDS:"+business.getTHISMONTHUNDERWRITEEDS()+",");
result.append("THISMONTHNOUNDERWRITEEDS:"+business.getTHISMONTHNOUNDERWRITEEDS()+",");
result.append("THISMONTHNOTEEDS:"+business.getTHISMONTHNOTEEDS()+",");
result.append("THISMONTHNONOTEEDS:"+business.getTHISMONTHNONOTEEDS()+",");
result.append("THISMONTHRECEIPTEDS:"+business.getTHISMONTHRECEIPTEDS()+",");
result.append("THISMONTHNORECEIPTEDS:"+business.getTHISMONTHNORECEIPTEDS()+",");
result.append("THISMONTHSURRENDEREDS:"+business.getTHISMONTHSURRENDEREDS()+",");
result.append("THISMONTHHEAREDS:"+business.getTHISMONTHHEAREDS());
result.append("}");

PrintWriter out = response.getWriter();
response.setContentType("text/html");
out.print(result.toString());
out.flush();
out.close();
------------------------------------------------------------------
3.HTML
$(function() {
//加载待处理业务数
$.ajax( {
url : "${path}/news/index/getBusiness",
type : 'POST',
success : function(result) {
var j = $("<span>" + result + "</span>").html();
var obj = eval("(" + j + ")");
$("#a1").html(obj.THISMONTHUNDERWRITEEDS);
$("#a2").html(obj.THISMONTHNOUNDERWRITEEDS);
$("#b1").html(obj.THISMONTHNOTEEDS);
$("#b2").html(obj.THISMONTHNONOTEEDS);
$("#c1").html(obj.THISMONTHRECEIPTEDS);
$("#c2").html(obj.THISMONTHNORECEIPTEDS);
$("#d1").html(obj.THISMONTHSURRENDEREDS);
$("#d2").html(obj.THISMONTHHEAREDS);
}

});
});
------------
(<em
id="a1"><img src="${path}/images/059.gif" style="width:10px;height:10px;"/></em>)
(<em
id="b1"><img src="${path}/images/059.gif" style="width:10px;height:10px;"/></em>)
(<em
id="c1"><img src="${path}/images/059.gif" style="width:10px;height:10px;"/></em>)

你可能感兴趣的:(jquery)