查询时动态检索springmvc + mabatis

来源:互联网 发布:阿里云域名解析cname 编辑:程序博客网 时间:2024/06/05 01:59

实现动态检索如


页面jsp


<form   action="<%=request.getContextPath() %>/admin/account/myuserbynameortele" method="post">
           <table >
         <tr>
                      
           <th>用户姓名</th>
           <td>
            <input type="text" name="username" id="username" />
           </td>
           
           
           <th>联系电话</th>
           <td>
            <input type="text" name="usertele" id="usertele" />
           </td>
           
           <td>
            <button id="qryEmp"  type="submit"
           iconCls="icon-search" class="easyui-linkbutton">查询</button>


           </td>
           
         </tr>
        </table>
      </form>



control

//检索根据用户姓名和联系电话

 @RequestMapping(value = "/myuserbynameortele",method = RequestMethod.POST)
 public String myuserbynameortele(Model model,String username,String usertele,HttpSession session) {
  
     Login  lo =(Login)session.getAttribute("loginUser");
  
  String userID=lo.getUserID();
  
  System.out.println(usertele);
  System.out.println(username);
 Pager<Accountinfo> acc = accountinfoService.listBynameortele(userID,username,usertele);
 
 
 model.addAttribute("datas",acc);
  System.out.println("aaaaaaaaaaaaaaaa");
    return "account/myuser";
  
 }
 

Iservice


/**
  *根据指定联系电话或者真实姓名检索
  * @param id
  */
 
 public Pager<Accountinfo> listBynameortele(String userID,String username,String usertele);


service


 /**
  * 获取子用户分页列表集合信息
  */
 @Override
 public Pager<Accountinfo> findaccount(String userID) {
  //获取子用户总数
  int count=accountDao.countzi(userID);
  /*
  //获取用户分页列表集合信息
  List<accountinfo> list = accountDao.findzi(userID);*/
  //封装PageBounds对象
  PageBounds pageBounds = PageBoundsUtil.PageBoundsOrderExtend("ID.asc");
  
  List<Accountinfo> list = accountDao.findzi(pageBounds,userID);
  
  //封装用户分页的Pager对象
  Pager<Accountinfo> pages = new Pager<Accountinfo>(count,list);
  return pages;
 }


dao

//根据电话和姓名查找
  public List<Accountinfo> findbynameortele(PageBounds pagebounds,Accountinfo acc);

 //根据电话和姓名查找 个数
 public int countbynameortele(Accountinfo acc);


 xml


 <!--根据电话或者姓名 查 讯当前帐户的所有子账户-->
 <select id="findbynameortele" parameterType="com.internet.cms.model.accountinfo.Accountinfo"    resultMap="accountinfo">
  select c.*
   from Wx_User_Info c  where 1=1
  <if test="_parameter.userID!=null and _parameter.userID!=''">
  and c.User_main_id =#{userID}
  </if>
   
  <if test="_parameter.username!=null and _parameter.username!=''">
   and c.User_name =#{username}
  </if>
  <if test="_parameter.usertele!=null and _parameter.usertele!=''">
   and c.User_tele = #{usertele}
  </if> 
 </select>
 
   <!--根据电话或者姓名 查询所有子用户的个数  -->
  <select id="countbynameortele" parameterType="com.internet.cms.model.accountinfo.Accountinfo" resultType="int">
 select count(*)
  from Wx_User_Info c where 1=1
  <if test="_parameter.userID!=null and _parameter.userID!=''">
  and User_main_id =#{userID}
  </if>
  <if test="_parameter.username!=null and _parameter.username!=''">
   and User_name =#{username}
  </if>
  <if test="_parameter.usertele!=null and _parameter.usertele!=''">
   and User_tele = #{usertele}
  </if>  
 </select>


xml和 jsp页面的书写




0 0
原创粉丝点击