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 !&quot;&quot;.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]的更多相关文章

  1. ajax请求 json格式和数组格式总结

    php echo json_encode($data); $.ajax({ url:APP+"?a=total&c=collection", //请求的页面 type:&q ...

  2. 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- ...

  3. Spring MVC 中 AJAX请求并返回JSON

    一.以ModelAndView的方式返回 先看下JavaScript代码: /** * 保存-同步(版本控制库) */ function saveSynchronizedVcHorse(obj) { ...

  4. 关于使用Ajax请求json数据,@RequestMapping返回中文乱码的几种解决办法

    一.问题描述: 使用ajax请求json数据的时候,无论如何返回的响应编码都是ISO-8859-1类型,因为统一都是utf-8编码,导致出现返回结果中文乱码情况. $.ajax({ type:&quo ...

  5. ReadyAPI/soapUI发送post请求json格式(带有中文字符),后台获取参数为空

    解决:请求编码格式默认为空,在"TestCase"的指定Step的Request Properties中, 改Encoding编码格式为UTF-8. 原文:soapUI发送post ...

  6. Django-choices字段值对应关系(性别)-MTV与MVC科普-Ajax发json格式与文件格式数据-contentType格式-Ajax搭配sweetalert实现删除确认弹窗-自定义分页器-批量插入-07

    目录 models 字段补充 choices 参数/字段(用的很多) MTV与MVC模型 科普 Ajax 发送 GET.POST 请求的几种常见方式 用 Ajax 做一个小案例 准备工作 动手用 Aj ...

  7. ajax发送json格式与文件数据、django自带的序列化器(了解)

    上期内容回顾 聚合查询和分组查询 # 聚合查询 max min sum avg count # 查询关键字:aggregate from django.db.models import Max, Mi ...

  8. play framework接收post请求json格式的参数

    大家在用play framework框架开发第三方调用你的接口的时候并且用json格式的参数post请求 ,参数接收是个问题 ,因为play对表单提交post请求有处理: 有两种方法: 1.直接形参列 ...

  9. robot framework 接口测试 http协议post请求json格式

    robot framework 接口测试 http协议post请求json格式 讲解一个基础版本.注意区分url地址和uri地址. rf和jmeter在添加服务器地址也就是ip地址的时候,只能url地 ...

随机推荐

  1. 五、Pandas玩转数据

    Series的简单运算 import numpy as np import pandas as pd s1=pd.Series([1,2,3],index=['A','B','C']) print(s ...

  2. shell脚本,文件里面的英文大小写替换方法。

    [root@localhost wyb]# cat daxiaoxie qweBNMacb eeeDFSmkl svdIOPtyu [root@localhost wyb]# cat daxiaoxi ...

  3. javase(1)_基础语法

    一.java概述 1.Java语言特点:纯面向对象(一切皆对象),平台无关(JVM屏蔽底层运行平台的差异),不同的平台有不同的JVM,JVM将程序翻译成当前操作系统能执行的程序,一次编译到处运行),健 ...

  4. Xcode 6 创建 Objective-C category

    1. Command + N 2. 选择 iOS - Source - Objective-C File 3.File Type 选择 Category,Class 填基于的类名,File填扩展的名

  5. initWithNibName:bundle awakeFromNib 区别

    initWithNibName:bundle 定义:is a message sent to a view (or window) controller in order to create the ...

  6. jquery 获取tbody下的第二个tr 及多级标签

    <div id="testSlider"> <div class="esriTimeSlider ies-Slider" id="t ...

  7. bzoj3545 [ONTAK2010]Peaks、bzoj3551 [ONTAK2010]Peaks加强版

    题目描述: bzoj3545,luogu bzoj3551 题解: 重构树+线段树合并. 可以算是板子了吧. 代码(非强制在线): #include<cstdio> #include< ...

  8. Linux-实现双主模型的nginx的高可用

    实现双主模型的ngnix高可用(一) 准备:主机7台 client: 172.18.x.x 调度器:keepalived+nginx 带172.18.x.x/16 网卡 192.168.234.27 ...

  9. Spring容器的理解

    控制反转(IOC,Inversion Of Contorl)和依赖注入(DI,Dependency Injection) IOC是一个宽泛的概念:对某事物的控制权由A转移到B. DI是实现IOC的一种 ...

  10. 在xcode上把你的app多语言国际化(NSLocalizedString)

    1.到project->info->localizations   下面的加号,添加你需要的语言 千万不要删除  base 否虽然我不知道有什么用,我是删了整个storyboard没了,很 ...