分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 代码编程

ssm+ajax异步请求返回list遍历

发布时间:2023-09-06 01:46责任编辑:顾先生关键词:遍历异步请求

jsp页面

<%@ page language="java" contentType="text/html; charset=UTF-8"
???pageEncoding="UTF-8"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<script type="text/javascript" src="js/jquery-1.5.js"></script>
<script type="text/javascript">

function findStudentInfo() {
debugger
???$.ajax({
???????type:"get",
???????url:"${pageContext.request.contextPath}/getemps",
???????dataType:"json",
???????success : function (data) {
???????debugger
???????????????$("#showMessageDiv").empty();
???????????????$("#showMessageDiv").append("<table id=‘table1‘></table>");
???????????????$("#table1").append("<tr><td>员工ID</td><td>姓名</td><td>性别</td><td>邮箱地址</td></tr>");
???????????????$.each(data,function (i,result) {
???????????????????var sex="女"
???????????????????if (result.gender==1){sex="男"}
???????????????????var item="<tr><td>"+result.id+"</td><td>"+result.lastName+"</td><td>"+sex+"</td><td>"+result.email+"</td>";
???????????????????$("#table1").append(item);
???????????????});
???????????
???????},
???error:function(){ ?
??????alert("错误");
???} ?
???});
}

</script>

<body>
<div>
异步请求响应
</div>
<div id="showMessageDiv">
</div>
<div id="data">
<input type="submit" id="getBtn" ?title="点击" onclick="findStudentInfo()"/>
</div>
</body>
</html>

2 action

@Controller
public class EmployeeController {

@Autowired
EmployeeService employeeService;

@RequestMapping("/getemps")
@ResponseBody
public String ?emps() throws JsonGenerationException, JsonMappingException, IOException{
List<Employee> emps = employeeService.getEmps();
ObjectMapper mapper= new ObjectMapper();
String jsonStr = mapper.writeValueAsString(emps );
System.out.println(jsonStr );
return jsonStr;
}

}

ssm+ajax异步请求返回list遍历

原文地址:https://www.cnblogs.com/zhangzhiqin/p/8592396.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved