Spring注解处理Ajax请求-JSON格式[系统架构:Spring+SpringMVC+MyBatis+MySql]
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了Spring注解处理Ajax请求-JSON格式[系统架构:Spring+SpringMVC+MyBatis+MySql],小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3749字,纯文字阅读大概需要6分钟。
内容图文
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]
标签:lin 系统 err 相同 str method list size 架构
本文系统来源:http://www.cnblogs.com/realvie/p/6476035.html
内容总结
以上是互联网集市为您收集整理的Spring注解处理Ajax请求-JSON格式[系统架构:Spring+SpringMVC+MyBatis+MySql]全部内容,希望文章能够帮你解决Spring注解处理Ajax请求-JSON格式[系统架构:Spring+SpringMVC+MyBatis+MySql]所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。