首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

Spring mvc 回来JSON

2013-03-22 
Spring mvc 返回JSONpublic ModelAndView updateContractTitle (HttpServletRequest request,??? HttpServ

Spring mvc 返回JSON

public ModelAndView updateContractTitle (HttpServletRequest request,
??? HttpServletResponse response) throws Exception {
??????? ModelAndView mav = new ModelAndView();
??????? long applyId = Long.valueOf(request.getParameter("applyId"));
??????? AbstractApply apply = applyDao.getApplyById(applyId);
??????? apply.setApplyTitle(request.getParameter("contractTitle"));
??????? for(Object t : apply.getApplyTarget()){
??????????? AbstractApplyTarget c = (AbstractApplyTarget) t;
??????????? c.setTitle(apply.getApplyTitle());
??????? }
??????? applyDao.merge(apply);//以上是业务逻辑

??????? //开始返回
??????? MappingJacksonJsonView view = new MappingJacksonJsonView();
??????? Map attributes = new HashMap();
??????? attributes.put("success", Boolean.TRUE);

?attributes.put("contractNo", "contractNo");

??????? view.setAttributesMap(attributes);
??????? mav.setView(view);
??????? return mav;
??? }

?

??var URL = "approve.do?action=approveC"? ? ? ? ? ? $.ajax({? ? ? ? ? ? ? ? type:"POST",? ? ? ? ? ? ? ? url:URL,? ? ? ? ? ? ? ? data:null,? ? ? ? ? ? ? ? success:function(msg){? ? ? ? ? ? ? ? ? ? alert(msg.contractNo);//取到返回的“contractNo”值? ? ? ? ? ? ? ? },? ? ? ? ? ? ? ? error:function(msg){? ? ? ? ? ? ? ? }? ? ? ? ? ? });

热点排行
Bad Request.