你的位置:首页 > Java教程

[Java教程]通配符的使用

1.   1.jsp

 1 <%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %> 2 <html> 3 <script type="text/javascript" src="${pageContext.request.contextPath}/js/jQuery1.11.1.js"></script> 4 <script type="text/javascript"> 5  $(function(){ 6   $("#btn").click(function(){ 7    $.ajax({ 8     url:"${pageContext.request.contextPath}/five", 9     success:function(data){ //data指的是从server打印到浏览器的数据10      /* $.each(data,function(i,dom){11       alert(dom.name);12       })*/13 14      $.each(data,function(i,dom){15       alert(dom.name);16      })17     }18    });19   });20  });21 22 </script>23 <body>24 <h2>ResponseBody</h2>25 <%--<form action="" method="post">--%>26 <input type="submit" id="btn" value="Ajax"/><%--</form>--%>27 </body>28 </html>
View Code

2.

 1 @Controller 2 public class FirstController { 3  @RequestMapping("/first") 4  @ResponseBody 5  public Object doFirst(){ 6   return 1; 7  } 8 @RequestMapping(value ="/second",produces = "text/html;charset=utf-8") 9  @ResponseBody10 public Object doSecond(){11  return "就业拼了";12  }13  @RequestMapping(value = "/third")14  @ResponseBody15  public Object doThird(){16   UserInfo info=new UserInfo();17   info.setName("白白");18   info.setAge(22);19   return info;20  }21 22 23  @RequestMapping(value = "/four")24  @ResponseBody25  public Object doFour(){26   Map<String,UserInfo> map=new HashMap<String, UserInfo>();27   UserInfo info=new UserInfo();28   info.setName("白白");29   info.setAge(20);30 31   UserInfo info2=new UserInfo();32   info2.setName("小熊啊");33   info2.setAge(22);34    map.put(info.getName(),info);35    map.put(info2.getName(),info2);36   return map;37  }38  @RequestMapping(value = "/five")39  @ResponseBody40  public Object doFive(){41   List<UserInfo> list=new ArrayList<UserInfo>();42   UserInfo info=new UserInfo();43   info.setName("白白");44   info.setAge(22);45   list.add(info);46   return list;47  }48 49 }
View Code

3.

1 public class UserInfo {2  private String name;3  private Integer age;4 }
View Code

4.

 1 <?"1.0" encoding="UTF-8"?> 2 <beans "" 3  "" 4  "" 5  "" "" 6  "" 7  xsi:schemaLocation=" > 8 http://www.springframework.org/schema/beans/spring-beans.xsd 9 http://www.springframework.org/schema/context10 http://www.springframework.org/schema/context/spring-context.xsd11 http://www.springframework.org/schema/tx12 http://www.springframework.org/schema/tx/spring-tx.xsd13 http://www.springframework.org/schema/aop14 http://www.springframework.org/schema/aop/spring-aop.xsd15 http://www.springframework.org/schema/mvc16 http://www.springframework.org/schema/mvc/spring-mvc.xsd">17 <context:component-scan base-package="cn.happy.controller"></context:component-scan>18  <mvc:annotation-driven/>19 </beans>
View Code