SSM框架jsp页面俩个参数作为查询条件查值显示在页面上

 

SSM框架jsp页面俩个参数作为查询条件查值显示在页面上_第1张图片

点击查询  把结果显示在下拉选单中

<body>

   <formid="form1"action=""method="post">

      <divclass="container-fluid">

          <ulclass="singbada-crumb">

             <li>当前位置:li>

             <li><ahref="#">首页a>li>

             <li>>li>

             <li><ahref="#">药房部a>li>

             <li>>li>

             <liclass="on">药品盘点li>

          ul>

          <divclass="singbada-conblock  form-horizontal">

             <h4class="singbada-form-h4">药房药品信息查询h4>

             <divclass="singbada-form-h4-con"align="center">

               <tablestyle="border-collapse:separate;border-spacing:40px;">

               <thead>

               <tr>

               <th>

                  <fontstyle="font-size:15px">开始时间font> <input class="jcDate"

                      style="width:180px;height:36px;line-height:20px;padding:4px;"

                      id="start"

                      name="startTime"

                      value=""/>

th>

<th>

                 <fontstyle="font-size:15px">结束时间font><input class="jcDate"

                      style="width:180px;height:36px;line-height:20px;padding:4px;"

                      name="endtime"

                      id="end"

                      value=""/>

                      th>

                      <th>

                       <inputclass="btnbtn-primary"type="button"id="btn1"value="查询">

                        th>  

                <th>

                 <fontstyle="font-size:15px">盘点单号font>

                 <selectid="select"name="pddh" style="width:180px;height:36px;line-height:20px;padding:4px;">

                      /*<c:forEachitems="${list}"var="d"varStatus="status">

                      <optionvalue="${d}">${d}option>           

                      c:forEach>*/这个方法适合list查询且不用AJAX

                select>

                 th>

                <th><fontid="msg">font>th>

                tr>

                thead>

          table>

             div>      

             <divclass="singbada-conblock  form-horizontal">

                <h4class="singbada-form-h4">查询结果h4>

                <divclass="singbada-form-h4-con">

                   <divclass="singbada-table-wrap">

                      <tableclass="tabletable-bordered table-hover">

                         <thead>

                             <tr>

                                <thwidth="4%">序号th>

<thwidth="15%">药品名称th>

                                <thwidth="15%">生产厂家th>

                                <thwidth="7%">药品规格th>

                                <thwidth="2%">单位th>

                                <thwidth="8%">进库价格th>

                                <thwidth="10%">零售价格th>

                                <thwidth="7%">盘点数量th>

                                <thwidth="7%">实际数量th>

                                <thwidth="10%">批发金额th>

                                <thwidth="10%">零售金额th>

                                <thwidth="5%">详细th>

                             tr>

                         thead>

                         <tbodyid="tbody">

                             <%-- var="holiday"varStatus="status">

                            

                                checkbox" name="box"

                                   value="${holiday.id}">

                               

                                ${holiday.userid}

                                ${holiday.leavetype}

                                ${holiday.deptid}

                                ${holiday.positionid}

                                ${holiday.teamid}

                                ${holiday.reasons}

                                ${holiday.workingarr}

                                ${holiday.status}

                                ${holiday.starttime}

                                ${holiday.endtime}

                                ${holiday.createtime}

                                ${holiday.createemp}                              

                                 

                         href="holiday/queryHolidayById.action?id=${holiday.id}">编辑                               

                            

                         --%>

                         tbody>

                      table>

                   div>

                div>

             div>

          div>

      div>

   form>

   <scripttype="text/javascript">

   //$("#end").blur(function()

   $("#btn1").click(function()//查询id

   //$("#end").change(function()

    {var start=$("#start").val();

      var end=$("#end").val();

      /* alert(start)

      alert(end) */

      var select=$("#select").val();//盘点单号id

      var s=start.replace(/\-/g,"")

      var v=end.replace(/\-/g,"")

      var t=s-v;

      //varresult=start.compareTo(end);   

   if(start.length<1){

     alert("请选择开始时间"

   }else if(end.length<1){

    alert("请选择结束时间")

   }else if(t>0){

   alert("开始时间不能大于结束时间")

   }else if(t==0){

   alert("开始时间不能等于结束时间")

   }else {

          $.post("querydh.action",$("#form1").serialize(),function(data){

                       $("#msg").html("查询成功");

                       alert(data);

                       varhtml ="";

                       $.each(data.list,function(k,v){

                       html += "+v.pddh+""

                       })

                       $("#select").html(html);

                       alert(html);

                    },"json");  

   }

   });  

   script>

body>

 

Controller层

    * 根据时间查询盘点单号

   @Controller

public class YaoFangController {

   @Autowired

   private YaoFangServer yfServer;

@RequestMapping("querydh")

   @ResponseBody //MAP集合转换成json格式在前端用date接收

   public Map querydh(HttpServletRequestrequest, StringstartTime,Stringendtime) {

//map 是接受后台传回来数据的容器   和 方法体 里的参数没有关系

      System.out.println("controlle1111111");

      /*String starttime1 =request.getParameter("starttime");

      String  endtime1 =request.getParameter("endtime");*/

      //System.out.println("controlle1"+starttime1+endtime1);

      //request.setAttribute("list", yfServer.querydh(time));//调试用的

      Listlist = yfServer.querydh(startTime,endtime);

      //request.setAttribute("list",list) ;

      System.out.println("controlle2222222");

      Mapmap = new HashMap();

      map.put("list",list);

      return map;

   }

 

 

server

public interface YaoFangServer {

   //药房根据时间查询盘点单号

  public List querydh(Stringstarttime,Stringendtime);

 

impl

  

   //时间查询单号

   @Override

   @ResponseBody

   public List querydh(Stringstarttime,Stringendtime)  {

      /*HttpServletRequest request = ServletActionContext.getRequest();

      Mapmap = new HashMap();

      Stringstarttime1 =request.getParameter(starttime1);

      String  endtime1 =request.getParameter(endtime);*/

      System.out.println("servere1111111");

      return yfMapper.querydh(starttime,endtime);

   }

 

 

MAPPER

public interface YaoFangMapper {

   /*

    * 根据时间查询盘点单号

    */

   Public List querydh(@Param("starttime") Stringstarttime,@Param("endtime")Stringendtime);

// List是 根据方法里的参数查询到的数据,这个数据是什么类型的list<>括号里就写什么

//一般都是把查询的数据封装起来一般都是封装类

//@Param("stime") Stringstarttime  其中@Param("stime")相当于String   后面参数的一个别名 ,//作用是在mapper.xml 查询时 写stime  就等同于 查询 starttime 参数值了

//例:WHERE    dbo.mz_yfpdd.pdsj>#{stime} and dbo.mz_yfpdd.pdsj < #{endtime};

//这个方法适合多个同时传多个参数

 

<mappernamespace="com.youmai.yixue.dao.YaoFangMapper">

 

 <selectid="pandian"parameterType="com.youmai.yixue.model.yaofang.YF_PanDian">

 SELECT     dbo.gy_ypml.ypmc ,dbo.gy_ypml.ypgg , dbo.mz_yfpddmx.pdsl , dbo.mz_yfpddmx.sjsl ,

                      dbo.gy_ypml.pjjkj ,  dbo.mz_yfpddmx.dj ,

                      dbo.mz_yfpddmx.pdsl *dbo.gy_ypml.pjjkj AS pfze,

                      dbo.mz_yfpddmx.pdsl *dbo.mz_yfpddmx.dj AS lsze

FROM        

                      dbo.gy_ypml INNER JOIN

                      dbo.mz_yfpddmx ongy_ypml.ypid= dbo.mz_yfpddmx.ypid

WHERE     dbo.mz_yfpddmx.pddh = #{test.pddh}

 

 select>

 //一定要有返回值类型(你要查询的那个表的字段如果是一个表里的那就把这个表的字段进行封装可以是所有的/可以是其中的几个字段/也可以是多个表中的字段)<是小于号 >是大于号的意思

  <selectid="querydh"resultType="com.youmai.yixue.model.yaofang.MZ_yfpdd">

  SELECT  dbo.mz_yfpdd.pddh 

FROM        

                     

     dbo.mz_yfpdd

WHERE    dbo.mz_yfpdd.pdsj>#{starttime}  and dbo.mz_yfpdd.pdsj< #{endtime};

 

  select>

SSM框架jsp页面俩个参数作为查询条件查值显示在页面上_第2张图片

你可能感兴趣的:(jsp多参查询)