Spring注解处理Ajax请求-JSON格式[系统架构:Spring+SpringMVC+MyBatis+MySql]
1.前端jsp页面
<div class="tab_tip">
请输入[身份证号或姓名]
<input type="text" class="tab_getText" id="tab1_getText"> <input type="button" class="tab_selectButton" id="tab1_selectButton" value="查询">
</div>
<!-- 省略代码 -->
<table class="table" id="table1" cellspacing="0" cellpadding="0">
<tr>
<th>个人编号</th>
<th>身份证号</th>
<th>姓名</th>
<th>性别</th>
<th>民族</th>
<th>出生年月</th>
<th>参加工作时间</th>
<th>缴费基数</th>
<th>单位编号</th>
<th>单位简称</th>
<th>人员状态</th>
</tr>
</table>
2. JavaScript处理代码
$(function(){
$("#tab1_selectButton").unbind('click').click(function(){
var tab1_getText = $.trim(document.getElementById("tab1_getText").value);
if(tab1_getText != ""){
$.ajax({
type:"POST",
url:"getStaffAllSelect/"+tab1_getText+"/0",
async:false,
dataType:"json",
success:function(data){
$(".staffallinfotr").remove();
for(i=0;i<data.length;i++){
$("#table1").append('<tr class="staffallinfotr"><td>'+data[i].sid+'</td><td>'+data[i].sino+'</td><td>'+data[i].sname+'</td><td>'+data[i].ssex+'</td><td>'+data[i].snation+'</td><td>'+data[i].sbirth+'</td><td>'+data[i].sdaj+'</td><td>'+data[i].pbase+'</td><td>'+data[i].cid+'</td><td>'+data[i].csn+'</td><td>'+data[i].sstate+'</td></tr>');
}
},
error:function(){
alert("error");
},
complete : function(XMLHttpRequest,status){
if(status=='timeout'){
ajaxTimeoutTest.abort();
alert("超时");
}
}
});
}else{
alert("请输入个人编号或姓名!");
}
});
});
3.Controller类中方法(注:StaffAllSelectDTO:和前端jsp页面中的table字段相同,因为代码过长,就不再贴出)
@RequestMapping("/getStaffAllSelect/{sname}/{start}")
public @ResponseBody List<StaffAllSelectDTO> getStaffAllSelect(@PathVariable String sname, @PathVariable int start){
List<StaffAllSelectDTO> staffAllSelectDTOList = staffServices.getStaffAllSelectByName(sname, start, 10);
for(int i=0;i<staffAllSelectDTOList.size();i++){
System.out.println(staffAllSelectDTOList.get(i));
}
return staffAllSelectDTOList;
}
4. Services类中方法
@Override
public List<StaffAllSelectDTO> getStaffAllSelectByName(String sname, int start, int limit) {
// TODO Auto-generated method stub
List<Staff> staffList = staffDAO.getStaffsByName(sname, start, limit);
List<StaffAllSelectDTO> staffAllSelectDTOList = staffFactory.staffAndStaffPaymentToStaffAllSelectDTO(staffList);
return staffAllSelectDTOList;
}
5. DAO类中方法
@Override
public List<Staff> getStaffsByName(String sname, int start, int limit) {
// TODO Auto-generated method stub
Map<String, Object> map = new HashMap<String, Object>();
map.put("sname", sname);
map.put("start", start);
map.put("limit", limit);
return getSqlSession().selectList("com.staff.entity.StaffMapper.getStaffsByName", map);
}
6. DTO: StaffAllSelectDTO:和前端jsp页面中的table字段相同,因为代码过长,就不再贴出)
7. Mybatis
<select id="getStaffsByName" parameterType="Map" resultMap="StaffResult">
select s.sid,s.sino,s.sname,s.ssex,s.snation,s.sbirth,s.sdaj,s.sstate,s.spbase,s.cid,c.csn,c.cname from staffinfo s, companyinfo c where s.cid = c.cid
<if test="sname != null and !"".equals(sname)">and s.sname like CONCAT('%',#{sname,jdbcType=VARCHAR},'%')</if>
<if test="start!=null and limit!=null">
limit #{start},#{limit}
</if>
</select>
Spring注解处理Ajax请求-JSON格式[系统架构:Spring+SpringMVC+MyBatis+MySql]的更多相关文章
- ajax请求 json格式和数组格式总结
php echo json_encode($data); $.ajax({ url:APP+"?a=total&c=collection", //请求的页面 type:&q ...
- springmvc4.0配置ajax请求json格式数据
1.导入相关jar包:jackson-annotation-2.5.4.jar,jackson-core-2.5.4.jar,jackson-databind-2.5.4.jar. 2.spring- ...
- Spring MVC 中 AJAX请求并返回JSON
一.以ModelAndView的方式返回 先看下JavaScript代码: /** * 保存-同步(版本控制库) */ function saveSynchronizedVcHorse(obj) { ...
- 关于使用Ajax请求json数据,@RequestMapping返回中文乱码的几种解决办法
一.问题描述: 使用ajax请求json数据的时候,无论如何返回的响应编码都是ISO-8859-1类型,因为统一都是utf-8编码,导致出现返回结果中文乱码情况. $.ajax({ type:&quo ...
- ReadyAPI/soapUI发送post请求json格式(带有中文字符),后台获取参数为空
解决:请求编码格式默认为空,在"TestCase"的指定Step的Request Properties中, 改Encoding编码格式为UTF-8. 原文:soapUI发送post ...
- Django-choices字段值对应关系(性别)-MTV与MVC科普-Ajax发json格式与文件格式数据-contentType格式-Ajax搭配sweetalert实现删除确认弹窗-自定义分页器-批量插入-07
目录 models 字段补充 choices 参数/字段(用的很多) MTV与MVC模型 科普 Ajax 发送 GET.POST 请求的几种常见方式 用 Ajax 做一个小案例 准备工作 动手用 Aj ...
- ajax发送json格式与文件数据、django自带的序列化器(了解)
上期内容回顾 聚合查询和分组查询 # 聚合查询 max min sum avg count # 查询关键字:aggregate from django.db.models import Max, Mi ...
- play framework接收post请求json格式的参数
大家在用play framework框架开发第三方调用你的接口的时候并且用json格式的参数post请求 ,参数接收是个问题 ,因为play对表单提交post请求有处理: 有两种方法: 1.直接形参列 ...
- robot framework 接口测试 http协议post请求json格式
robot framework 接口测试 http协议post请求json格式 讲解一个基础版本.注意区分url地址和uri地址. rf和jmeter在添加服务器地址也就是ip地址的时候,只能url地 ...
随机推荐
- 获得stixel的gt数据
这是论文中的作者博客地址https://sites.google.com/site/danmlevi/ 这是作者现在的博客地址https://sites.google.com/view/danlevi ...
- 利用python进行数据分析3_Pandas的数据结构
Series #通过list构建Series ser_obj=pd.Series(range(10,20)) print(type(ser_obj))#<class 'pandas.core.s ...
- Encryption-基础:MD5加密
环境:vc2003 .h /* MD5.H - header file for MD5C.C */ /* Copyright (C) 1991-2, RSA Data Security, Inc. C ...
- blog.yiz96.com
欢迎访问我的新博客 blog.yiz96.com
- Java中的线程--线程中的工具
这主要想写一下Java中的jdk提供的一些线程中的工具, 一.semaphore信号灯 Semaphore可以维护当前访问自身的线程个数,并提供了同步机制,使用Semaphore可以控制同时访问资源的 ...
- html节点类型
<li> nodeType:节点类型: <br> 1--->Element节点: <br> 3--->Text节点: <br> 8---&g ...
- 【树链剖分 差分】bzoj3626: [LNOI2014]LCA
把LCA深度转化的那一步还是挺妙的.之后就是差分加大力数据结构了. Description 给出一个n个节点的有根树(编号为0到n-1,根节点为0).一个点的深度定义为这个节点到根的距离+1.设dep ...
- 对linux中source,fork,exec的理解以及case的 使用
fork 使用 fork 方式运行 script 时, 就是让 shell(parent process) 产生一个 child process 去执行该 script, 当 child proc ...
- nw335 debian sid x86-64 --3 linux内核自带
nw335 debian sid x86-64 --3 linux内核自带
- awk支持多个记录分隔符的写法
awk的-F参数可以指定新的记录分隔符,有些时候可能需求指定多个分隔符,比如下面的内容 width:720 height:360 如果需要取出width和height后面的值的话,一般大家会这样做,即 ...