springmvc json 简单例子
1.控制器层:
@RequestMapping("/json.do")
@ResponseBody
//将会把返回值 转换为json对象
public List<User> json(){
List<User> list = new ArrayList<User>();
list.add(new User(1,"zhansan",22));
list.add(new User(2,"wangwu",21));
list.add(new User(3,"zhaosi",33));
list.add(new User(4,"wangdana",14));
return list;
}
2.jsp页面:
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>"> <title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<script type="text/javascript" src="js/jquery-1.11.3.min.js"></script>
<script type="text/javascript">
$(function(){
$('#btn').click(function(){
$.post("json.do",function(data){
var html="";
for(var i=0;i<data.length;i++){
html+="<tr><td>"+data[i].id+"</td><td>"+data[i].name+"</td><td>"+data[i].age+"</td></tr>"
}
$('#content').html(html);
});
});
});
</script> </head> <body>
<input type="button" id="btn" value="获取数据"/><br>
<table width="80%" align="center">
<tr>
<td>编号</td>
<td>姓名</td>
<td>年龄</td>
</tr>
<tbody id="content"></tbody>
</table>
</body>
</html>
springmvc json 简单例子的更多相关文章
- JSON 简单例子
代码: json [ { "title" : "a", "num" : 1 }, { "title" : "b ...
- springMVC初学简单例子
新建web项目,保留web.xml. 配置web.xml文件(/WEB-INF/下): <?xml version="1.0" encoding="UTF-8&qu ...
- springmvc+ehcache简单例子
这里采用的是spring3.2.ehcache2.7.tomcat7.0(必须) 1.web.xml <?xml version="1.0" encoding="U ...
- springmvc ajax 简单例子
1.控制器曾 @Controller public class AjaxController { @RequestMapping("/ajax") public void ajax ...
- php+jquery+ajax+json简单小例子
直接贴代码: <html> <title>php+jquery+ajax+json简单小例子</title> <?php header("Conte ...
- android json解析及简单例子+Android与服务器端数据交互+Android精彩案例【申明:来源于网络】
android json解析及简单例子+Android与服务器端数据交互+Android精彩案例[申明:来源于网络] android json解析及简单例子:http://www.open-open. ...
- SpringMvc(注解)上传文件的简单例子
spring mvc(注解)上传文件的简单例子,这有几个需要注意的地方1.form的enctype=”multipart/form-data” 这个是上传文件必须的2.applicationConte ...
- SpringMVC之简单的增删改查示例(SSM整合)
本篇文章主要介绍了SpringMVC之简单的增删改查示例(SSM整合),这个例子是基于SpringMVC+Spring+Mybatis实现的.有兴趣的可以了解一下. 虽然已经在做关于SpringMVC ...
- jsonp的简单例子
jsonp的简单例子 index.html <!DOCTYPE html> <html> <head> <meta charset="UTF-8&q ...
随机推荐
- 全面解析Bootstrap手风琴效果
触发手风琴可以通过自定义的data-toggle 属性来触发.其中data-toggle值设置为 collapse,data-target="#折叠区标识符". 第一步:设计一个面 ...
- Python基础-数据写入execl
import xlwt book = xlwt.Workbook()#创建一个excel sheet = book.add_sheet('lanxia')#添加一个sheet页 title = ['姓 ...
- BEC listen and translation exercise 44
But over the past 70 years or so, there's been a massive increase in one type of crime which was wha ...
- VC++6.0编译环境介绍
大家可能一直在用VC开发软件,但是对于这个编译器却未必很了解.原因是多方面的.大多数情况下,我们只停留在"使用"它,而不会想去"了解"它.因为它只是一个工具,我 ...
- Java中的参数传值方式
本文转载自 https://blog.csdn.net/SEU_Calvin/article/details/70089977 1. 你觉得下面程序会输出什么 public static void ...
- 【LeetCode】019. Remove Nth Node From End of List
Given a linked list, remove the nth node from the end of list and return its head. For example, Give ...
- 服务注册选型比较:Consul vs Zookeeper vs Etcd vs Eureka
zookeeper基于paxos的化简版zab,etcd基于raft算法.consul也是基于raft算法.etcd和consul作为后起之秀,并没有因为已经有了zookeeper而放弃自己,而是采用 ...
- node好用的东东
supervisor 可参考: http://www.cnblogs.com/pigtail/archive/2013/01/08/2851056.html http://www.cnblogs.co ...
- HDU1548(楼梯问题bfs)
#include"cstdio" #include"queue" #include"cstring" using namespace std ...
- 微服务理论之五:微服务架构 vs. SOA架构
一.面向服务的架构SOA 面向服务的架构是一种软件体系结构,应用程序的不同组件通过网络上的通信协议向其他组件提供服务.通信可以是简单的数据传递,也可以是两个或多个服务彼此协调连接.这些独特的服务执行一 ...