600 考勤管理 查询部门
DeptServlet
//查询部门信息
protected void deptFindAll1(HttpServletRequest req,
HttpServletResponse resp) throws ServletException, IOException {
List<Dept> list = deptService.findAll();
String json = new Gson().toJson(list);
resp.getWriter().print(json);
}
dutyList.html
<script>
$(function () {
$.post("sxt/DeptServlet","method=deptFindAll1",function (result) {
for(var i in result){
$("#dept").append('<option value="'+result[i].deptno+'">'+result[i].deptname+'</option>');
}
},"json")
})
</script>
<i>所属部门</i>
<a>
<select class="select1" id="dept">
<option>--请选择--</option>
</select>
</a>
601 考勤管理 查询考勤管理A
三表联查!
select * from duty d JOIN employee e on d.emprid = e.empid join dept de on e.deptno=de.deptno
1 实体类Duty
public class Duty implements Serializable {
private Integer dtID;
private String emprId;
private Date dtDate;
private String signinTime;
private String signoutTime;
//增加属性
private String realName;
private String deptName;
2 DutyMapper DutyMapper.xml
<select id="selectMore" resultType="duty">
select * from duty d JOIN employee e on d.emprid = e.empid join dept de on e.deptno=de.deptno
<where>
<if test="param1!=null and param1!=''">
d.emprid=#{param1}
</if>
<if test="param2!=null and param2!=''">
and e.deptno=#{param2}
</if>
<if test="param3!=null and param3!=''">
and d.dtdate=#{param3}
</if>
</where>
</select>
//查询考勤信息
List<Duty> selectMore(String empid,String deptno,String dtdate);
3 DutyService DutyServiceImpl
@Override
public List<Duty> findMore(String empid, String deptno, String dtdate) {
DutyMapper mapper = DBUtil.getSqlSession().getMapper(DutyMapper.class);
List<Duty> list = mapper.selectMore(empid, deptno, dtdate);
DBUtil.closeAll();
return list;
}
//查询指定用户考勤信息
List<Duty> findMore(String empid,String deptno,String dtdate);
4 DutyServlet
//查询指定用户考勤的信息
protected void dutyFindMore(HttpServletRequest req,
HttpServletResponse resp) throws ServletException, IOException {
String empid = req.getParameter("empid");
String deptno = req.getParameter("deptno");
String dtdate = req.getParameter("dtdate");
List<Duty> list = dutyService.findMore(empid, deptno, dtdate);
String json = new Gson().toJson(list);
resp.getWriter().print(json);
}
5 dutyList.html
<script>
$(function () {
$.post("sxt/DeptServlet","method=deptFindAll1",function (result) {
for(var i in result){
$("#dept").append('<option value="'+result[i].deptno+'">'+result[i].deptname+'</option>');
}
},"json")
})
function demo1() {
//序列化表单
var val =$("#fm").serialize();
alert(val);
$.post("sxt/DutyServlet?method=dutyFindMore",val,function
(result) {
},"json")
}
</script>
<div class="rightinfo">
<form action="" method="post">
<ul class="prosearch">
<li>
<label>查询:</label><i>用户名</i>
<a>
<input name="empid" type="text" class="scinput" />
</a><i>所属部门</i>
<a>
<select name="deptno" class="select1" id="dept">
<option>--请选择--</option>
</select>
</a>
<i>考勤时间</i>
<a>
<input name="dtdate" type="text" class="scinput" />
</a>
<a>
<input name="" type="submit" class="sure" value="查询" />
</a>
<a>
<input name="" type="button" class="scbtn2" value="导出"/>
</a>
</li>
</ul>
</form>
#号不要忘记写
var val =$("#fm").serialize();
and 不要忘记写
d.emprid=#{param1} and e.deptno=#{param2} and d.dtdate=#{param3}602 考勤管理 查询考勤管理B
dutyList.jsp
<script>
$(function () {
$.post("sxt/DeptServlet","method=deptFindAll1",function (result) {
for(var i in result){
$("#dept").append('<option value="'+result[i].deptno+'">'+result[i].deptname+'</option>');
}
},"json")
demo1();
})
function demo1() {
//序列化表单
var val =$("#fm").serialize();
$.post("sxt/DutyServlet?method=dutyFindMore",val,function
(result) {
$("#tb").empty();
for(var i in result){
$("#tb").append('<tr>\n' +
'<td>\n' +
'<input name="" type="checkbox" value="" />\n' +
'</td>\n' +
'<td>'+result[i].emprId+'</td>\n' +
'<td>'+result[i].realName+'</td>\n' +
'<td>'+result[i].deptName+'</td>\n' +
'<td>'+result[i].dtDate+'</td>\n' +
'<td>'+result[i].signinTime+'</td>\n' +
'<td>'+result[i].signoutTime+'</td>\n' +
'</tr>\n' +
'\n')
}
},"json")
}
</script>
如何改变日期格式?
DutyServlet
protected void dutyFindMore(HttpServletRequest req,
HttpServletResponse resp) throws ServletException, IOException {
String empid = req.getParameter("empid");
String deptno = req.getParameter("deptno");
String dtdate = req.getParameter("dtdate");
List<Duty> list = dutyService.findMore(empid, deptno, dtdate);
// String json = new Gson().toJson(list);
Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd").create();
String json = gson.toJson(list);
resp.getWriter().print(json);
}
603 考勤管理 POI数据导出A
点击导出,变成excel表!
package com.bjsxt.util;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.ss.util.CellRangeAddress;
/*
OutputStream out = response.getOutputStream();
//response.reset();
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-disposition", "attachment; fileName=" + new String(("duty.xls").getBytes(), "iso8859-1"));
// OutputStream outputStream = new FileOutputStream("D:/students.xls");
workbook.write(out);
out.close();
*/
public class ExcelOperate {
public static void main(