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. C#在透明窗体WinForm上面画图(电子尺小工具的实现)

    前几天要做一个微信调一调的外挂,里面用到了尺子测量距离,然后就自己下载了一个电子尺,最近要升级我的跳一跳外挂,然后就准备自己做一个电子尺,嵌入到我的外挂里面,在嵌入到我的外挂之前,我自己做了一个完整版 ...

  2. 使用Xcode连接开源中国

    故事背景: 今天加入一个新的项目组,其实也就是包括我在内就两个人,由于对方在开源中国上建的项目我没法使用. 所以由我接手第一个任务:就是在开源中国上搭建git项目组 前提条件:xcode和 Git(h ...

  3. bzoj5368 [Pkusc2018]真实排名

    题目描述: bz luogu 题解: 组合数计数问题. 首先注意排名指的是成绩不小于他的选手的数量(包括他自己). 考虑怎么增大才能改变排名. 小学生都知道,对于成绩为$x$的人,让他自己不动并让$\ ...

  4. python3.x中的33个保留字

    Python 3.6.4 (v3.6.4:d48eceb, Dec 19 2017, 06:04:45) [MSC v.1900 32 bit (Intel)] on win32 Type " ...

  5. 【Python学习之一】list与tuple

    list -> [] list是python内置的有序集合数据类型,可随时添加和删除元素.例如:创建一个动物的列表: animal = ['cat', 'dog', 'pig' len()函数可 ...

  6. GIMP图片头发的处理

    1/选中图片,添加Alpha Channel 2/点击Duplicate Layer,复制图层: 3/接着需要调整一下色差,选中Color下的Curves,调节曲线,使背景看起来更白一点 4/选中Co ...

  7. ubuntu下如何对接斗鱼直播

    参考教程:https://www.cnblogs.com/liuxuzzz/p/5315998.html 大神写得挺细的,这里都不想再多说了! 为啥要做这个呢?可能真的只是为了好玩吧!!有兴趣直播的孩 ...

  8. The US in understimating Huawei, says founder Ren zhengfei

    Huawei Founder Ren Zhengfei has downplayed the impact of the US executive order that cripple Huawei' ...

  9. springboot elk实时日志搭建

    https://blog.csdn.net/yy756127197/article/details/78873310 基本的上的过程如这篇博客,logback的配置文件和依赖不太一样 具体见源码其中的 ...

  10. Java-字符串大小写转换

    package com.tj; public class MyClass implements Cloneable { public static void main(String[] args) { ...