Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2538382
  • 博文数量: 245
  • 博客积分: 4125
  • 博客等级: 上校
  • 技术积分: 3113
  • 用 户 组: 普通用户
  • 注册时间: 2009-03-25 23:56
文章分类

全部博文(245)

文章存档

2015年(2)

2014年(26)

2013年(41)

2012年(40)

2011年(134)

2010年(2)

分类: Java

2011-10-31 14:00:02

在前一篇文章spring mvc json 实例代码里面,我们已经知道怎样从spring mvc中输出json数据。
这篇文章主要说明怎样在视图页面里处理json数据。

画面描述:当我们点击autosearchresumebtn这个按钮时,触发click事件,以post方式将参数positionid发送给控制器里的方法autosearchresume.do  在该方法中会根据positionid查询出与之相匹配的resume对象集合,并返回。json中存放的便是List

视图页面jquery代码:
  1. $(function() {
  2.     $("#autosearchresumebtn").click(function(){
  3.     
  4.         alert($("#positionid").val());
  5.        $.post("${pageContext.request.contextPath}/autosearchresume.do",
  6.                    {positionid: $("#positionid").val()
  7.                    },
  8.                    function(json){
  9.                      var html = "";
  10.                      for(resume in json){
  11.                          html += "
  12. "
  13.                          html += "
  14. ";
  15.                          html += "
  16. ";
  17.                          html += "
  18. ";
  19.                          html += "
  20. ";
  21.                          html += "
  22. ";
  23.                          html += "
  24. ";
  25.                          //alert(json[resume].nature);
  26.                          // alert(json[resume].education);
  27.                         
  28.                          html += "
  29. ";
  30.                      }
  31.                      html += "
  32. " +""+json[resume].name+""+json[resume].experience+""+json[resume].age+""+json[resume].nature+""+json[resume].education+"
    "
    ;
  33.                      alert(html);
  34.                      $('#tip').replaceWith(html);
  35.                     
  36.                     
  37.                     
  38.                    });
  39.     });
  40. });

控制器代码:
  1. //auto search resumes for a postion
  2.         @RequestMapping(value="/autosearchresume.do", method = RequestMethod.POST)
  3.         public @ResponseBody List<Resume> autoSearchResume(
  4.                 @RequestParam(value = "positionid", required = true) int positionid
  5.                 ){
  6.              Resume condition = new Resume();
  7.              Position position = positionMgr.get(positionid);
  8.              condition.setEducation(position.getEducation());
  9.              condition.setNature(position.getNature());
  10.             
  11.              List<Resume> ret = resumeMgr.autosearch(condition);
  12.         
  13.             return ret;
  14.         }

谢谢访问!

阅读(2970) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~