点击查询 把结果显示在下拉选单中
<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">
<%-- <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 < #{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>