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地 ...
随机推荐
- Maven01
1. Maven简单介绍 Apache Maven是个项目管理和自动构建工具,基于项目对象模型(POM)的概念. 作用:完成项目的相关操作,如:编译,构建,单元测试,安装,网站生成和基于Maven部 ...
- python hdfs初体验
新建目录 chr 新建文件hdfstest1.txt并写入内容 复制hdfstest1.txt的内容到hdfstest2.txt
- BZOJ1009: [HNOI2008]GT考试 (矩阵快速幂 + DP)
题意:求一个长度为n的数字字符串 (n <= 1e9) 不出现子串s的方案数 题解:用f i,j表示长度为i匹配到在子串j的答案 用kmp的失配函数预处理一下 然后这个转移每一个都是一样的 所以 ...
- jsTree展开根节点 设置用户图标
$("#jstree").on("loaded.jstree", function (event, data) { var n = 0; var root = ...
- shell脚本,在指定目录下通过随机小写10个字母加固定字符串oldboy批量创建10个html文件。
[root@localhost wyb]# cat test10.sh #!/bin/bash #使用for循环在/test10目录下通过随机小写10个字母加固定字符串oldboy批量创建10个htm ...
- iMessage, Facetime 解决办法
不需要白苹果三码,亲测可用:原帖地址: https://www.reddit.com/r/hackintosh/comments/2wohwn/getting_imessage_working_on_ ...
- ubuntu 安装 php7.2
sudo apt-get install software-properties-common python-software-properties sudo add-apt-repository p ...
- laravel如何利用数据库的形式发送通知
具体实现需要分几步: 1.修改驱动为database; 2.创建database的queue表 3.创建任务sendMessage 4.创建发送逻辑dispatch 5.启动队列 接下来我们进行实操: ...
- redis 内存管理与数据淘汰机制(转载)
原文地址:http://www.jianshu.com/p/2f14bc570563?from=jiantop.com 最大内存设置 默认情况下,在32位OS中,Redis最大使用3GB的内存,在64 ...
- 面试准备——java设计模式
1 总体来说,设计模式分为三大类: 设计模式(design pattern)是对软件设计中普遍存在(反复出现)的各种问题,所提出的解决方案. 创建型模式(五种):工厂方法模式.抽象工厂模式.单例模式. ...