public interface EmpDao {
/**
* 获取雇员总数量
* @return
*/
public int searchAll(Map map);
public List search(Map map);
}
mapper映射文件
select count(*) from emp
and sal > #{minSal}
select empno,ename,sal from
(select rownum r ,e.* from emp e
where e.sal > #{minSal}
) a where a.r > #{start}
and a.r < #{end}
业务层接口
//业务层的接口
public interface IEmpService {
//分页;
public PageData getList(Map map);
}业务层接口的实现类
@Service("service")
public class EmpService implements IEmpService {
//注入,byName类型;
@Resource
private EmpDao empDao;//数据层;
public PageData getList(Map map) {
PageData pageData=new PageData(empDao.searchAll(map),empDao.search(map));
return pageData;
}
}控制器代码
@Controller
@RequestMapping("/emp") //窄化处理
public class EmpController {
//自动注入
@Resource
private IEmpService service;
@RequestMapping("/list")
public String getList(Model model){//Model:模型,只存数据
Listlist=service.getList();
model.addAttribute("size",list.size());
model.addAttribute("list",list);//存放集合
return "test2";//返回到list页面
}
//分页
@RequestMapping("/list2")
public String list(Model model,Integer pageNo,Integer minSal,HttpServletRequest request){
System.out.println("URI地址:"+request.getRequestURI());
//Enumeration pNames=request.getParameterNames();
// while(pNames.hasMoreElements()){
// String name=(String)pNames.nextElement();
// System.out.println("name:"+name+"="+request.getParameter(name));
// }
int pageSize=3;
if(pageNo==null){
pageNo=1;
}
Map map =new HashMap();
map.put("start", (pageNo-1)*pageSize);
map.put("end", pageNo*pageSize+1);
map.put("minSal",minSal);
PageData pageData = service.getList(map);
int count = pageData.getCount();//总数量
String pageString = new PageUtil(pageSize, pageNo, count, request).getPageString();
model.addAttribute("list", pageData.getList());
model.addAttribute("pageString", pageString);
return "list";
}
}前端页面list.jsp页面
最低工资:
最高工资:
工号 | 姓名 | 工资 | 操作 |
${emp.empno } | ${emp.ename } | ${emp.sal } | |
${pageString} |
正常带查询的坟茔应该是如下状态
按时间查询,在入职日期输入一个时间,点击datetimebox,选择相应的时间
mapper文件代码:
select * from (select rownum r ,e.empno,e.ename,e.age,e.sex,e.email,e.ephone,p.pname,dt.dname,d.dromroom,e.eaddress,e.hiredate,e.leavedate from T_emp e left join
T_drom d on e.dromno=d.dromno left join T_dept dt on e.deptno=dt.deptno left join T_position p on e.pno=p.pno
and e.empno=#{empno}
and e.ename like '%${ename}%'
and e.hiredate=to_date('${hiredate}','yyyy-mm-dd')
)a
where a.r > #{start}
and a.r < #{end}
控制器代码:
@RequestMapping("/getemps")
public String list(Model model,Integer pageNo,HttpServletRequest request,Integer empno,String ename,Date hiredate){
System.out.println("URI地址:"+request.getRequestURI());
int pageSize=5;//每页条数
if(pageNo==null){
pageNo=1;
}
Map map =new HashMap();
map.put("start", (pageNo-1)*pageSize);
map.put("end", pageNo*pageSize+1);
map.put("empno",empno);
map.put("ename", ename);
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
if(hiredate!=null){
String s=sdf.format(hiredate);
System.out.println(s);
map.put("hiredate", s);
}
PageData pageData =empservice.getList(map);
int count = pageData.getCount();//总数量
String pageString = new PageUtil(pageSize, pageNo, count, request).getPageString();
model.addAttribute("emps", pageData.getList());
model.addAttribute("pageString", pageString);
return "emp/getemps";
}注意实体类型是java.sql.date,可以直接查询。