1. 程式人生 > >SSM框架jsp頁面倆個引數作為查詢條件查值顯示在頁面上

SSM框架jsp頁面倆個引數作為查詢條件查值顯示在頁面上


點選查詢  把結果顯示在下拉選單中

<body>

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

      <divclass="container-fluid">

          <ulclass="singbada-crumb">

             <li>當前位置:</li>

             <li><ahref="#">首頁</a></li>

             <li>&gt;</

li>

             <li><ahref="#">藥房部</a></li>

             <li>&gt;</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">

                             <%-- <c:forEach items="${list}"var="holiday"varStatus="status">

                             <tr>

                                <td><inputtype="checkbox" name="box"

                                   value="${holiday.id}">

                                <inputtype="hidden" name="id" value="${holiday.id}"></td>

                                <td>${holiday.userid}</td>

                                <td>${holiday.leavetype}</td>

                                <td>${holiday.deptid}</td>

                                <td>${holiday.positionid}</td>

                                <td>${holiday.teamid}</td>

                                <td>${holiday.reasons}</td>

                                <td>${holiday.workingarr}</td>

                                <td>${holiday.status}</td>

                                <td>${holiday.starttime}</td>

                                <td>${holiday.endtime}</td>

                                <td>${holiday.createtime}</td>

                                <td>${holiday.createemp}</td>                              

                                 <td>

                         <ahref="holiday/queryHolidayById.action?id=${holiday.id}">編輯</a>                                </td>

                             </tr>

                         </c:forEach>--%>

                         </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 += "<option value='"+v.pddh+"'>"+v.pddh+"</option>"

                       })

                       $("#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<String,Object> 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));//除錯用的

      List<MZ_yfpdd>list = yfServer.querydh(startTime,endtime);

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

      System.out.println("controlle2222222");

      Map<String,Object>map = new HashMap<String,Object>();

      map.put("list",list);

      return map;

   }

server

public interface YaoFangServer {

   //藥房根據時間查詢盤點單號

  public List<MZ_yfpdd> querydh(Stringstarttime,Stringendtime);

impl

   //時間查詢單號

   @Override

   @ResponseBody

   public List<MZ_yfpdd> querydh(Stringstarttime,Stringendtime)  {

      /*HttpServletRequest request = ServletActionContext.getRequest();

      Map<String,Object>map = new HashMap<String, Object>();

      Stringstarttime1 =request.getParameter(starttime1);

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

      System.out.println("servere1111111");

      return yfMapper.querydh(starttime,endtime);

   }

MAPPER

public interface YaoFangMapper {

   /*

    * 根據時間查詢盤點單號

    */

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

// List<MZ_yfpdd>是 根據方法裡的引數查詢到的資料,這個資料是什麼型別的list<>括號裡就寫什麼

//一般都是把查詢的資料封裝起來一般都是封裝類

//@Param("stime") Stringstarttime  其中@Param("stime")相當於String   後面引數的一個別名 ,//作用是在mapper.xml 查詢時 寫stime  就等同於 查詢 starttime 引數值了

//例:WHERE    dbo.mz_yfpdd.pdsj>#{stime} and dbo.mz_yfpdd.pdsj &lt; #{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>

 //一定要有返回值型別(你要查詢的那個表的欄位如果是一個表裡的那就把這個表的欄位進行封裝可以是所有的/可以是其中的幾個欄位/也可以是多個表中的欄位)&lt;是小於號 &gt;是大於號的意思

<!-- 藥房盤點單號 -->

  <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&lt; #{endtime};

  </select>