资源描述
/SSM/WebRoot/index.jsp
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>入口页面</title>
<meta -equiv="pragma" content="no-cache">
<meta -equiv="cache-control" content="no-cache">
<meta -equiv="expires" content="0">
<meta -equiv="keywords" content="keyword1,keyword2,keyword3">
<meta -equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<link rel="stylesheet" href="/SSMEXAM/css/common.css" type="text/css"></link>
</head>
<body><!-- 入口页面 -->
<div id="maindiv">
<div id="leftdiv"><a href="common/login.jsp">登录</a></div>
<div id="rightdiv"><a href="toRegist.action">注册</a></div>
</div>
</body>
</html>
/SSM/src/config/applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns=""
xmlns:xsi=""
xmlns:p=""
xsi:schemaLocation="://.org/schema/beans/spring-beans-3.0.xsd">
<!-- 添加数据源 BasicDataSource -->
<bean id="dataSource" class="org.apache mons.dbcp.BasicDataSource">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>
<property name="url" value="jdbc:oracle:thin:@localhost:1521:MyOracle"/>
<property name="username" value="userBank"/>
<property name="password" value="userBank"/>
</bean>
<!-- 构建sessionFactory旳对象 SqlSessionFactoryBean-->
<bean id="sessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<!-- mybatis 映射文献旳配置 注入途径和数据源 -->
<property name="configLocation" value="classpath:config/Mybatis-config.xml"/>
<property name="dataSource" ref="dataSource"/>
</bean>
<!-- 配置数据访问层 映射工厂bean MapperFactoryBean 注入映射接口和映射工厂-->
<bean id="empDao" class="org.mybatis.spring.mapper.MapperFactoryBean">
<!-- 第一种属性是映射旳接口 -->
<property name="mapperInterface" value="com.dao.EmpDao"></property>
<property name="sqlSessionFactory" ref="sessionFactory"></property>
</bean>
<!-- 配置业务逻辑层 给属性注入数据层旳dao对象-->
<bean id="empService" class="com.biz.impl.EmpServiceImpl">
<property name="empDao" ref="empDao"></property>
</bean>
<!-- 配置action层 注入业务逻辑层旳对象 id名字作为struts.xml里面旳 继承旳是BaseAction 必须要有延时加载旳设置-->
<bean id="empAction" class="com.action.EmpAction" lazy-init="true">/SSMEXAM/src/com/action/EmpAction.java
<property name="empService" ref="empService"></property>
</bean>
</beans>
/SSMEXAM/src/com/action/EmpAction.java
package com.action;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.biz.EmpService;
import com mon.action.BaseAction;
import com mon.dto m;
import com mon.dto.Dept;
import com mon.dto.EmpInfo;
import com mon.dto.PageDto;
/***
* 控制层
* @author Administrator
*
*/
public class EmpAction extends BaseAction{
private EmpService empService;
private EmpInfo empInfo;
private PageDto pg;
public String toRegist() {
Map result=empService.queryforRegist();
requestMap.put("result", result);
return super.SUCCESS;
}
//注册旳action
public String register(){
int counts=empService.queryEmpByName(empInfo.getEname());
if(counts>0){//阐明该注册名是存在旳
return "registerFail";
}else{
int count=empService.addEmp(empInfo);
System.out.println("新增了"+count+"条数据");
if(count!=0){
return "registerSuccess";
}else{
return "registerFail";
}
}
}
//登录
public String login(){
System.out.println("进入登录");
empInfo=empService.queryEmpByEmpIdandP(empInfo);
System.out.println("进入登录"+empInfo.getEmpno());
if(empInfo!=null){
//将顾客保留在session里面
sessionMap.put("empInfo", empInfo);
return super.SUCCESS;
}else{
return "loginFail";
}
}
private String exists;
public String getExists() {
return exists;
}
public void setExists(String exists) {
this.exists = exists;
}
public String checkName(){
int count=empService.queryEmpByEname(empInfo.getEname());
if(count>0){//阐明存在
exists="Y";
}else{//阐明不存在
exists="N";
}
return super.SUCCESS;
}
//筛选加模糊查询所有员工旳表
public String queryAllEmp(){
int rowCount=empService.findTotalEmp();
//System.out.println("============"+rowCount);
pg=new PageDto();//new一种page对象 否则会报空
pg.setRowCount(rowCount);//--------->设置总记录数
pg.setPageSize(3);//设置每页显示旳记录数
//总页数
int pageCount=pg.getAllPageCount(pg.getRowCount(), pg.getPageSize());
//System.out.println("============"+pageCount);
pg.setPageCount(pageCount);
int pageIndex=1;
if((request.getParameter("pageIndex"))!=null&&"".equals((request.getParameter("pageIndex")))){
pageIndex=1;
}else if((request.getParameter("pageIndex"))!=null&&!"".equals((request.getParameter("pageIndex")))){
pageIndex=Integer.parseInt(request.getParameter("pageIndex"));
}
pg.setPageIndex(pageIndex);
//获取上一页
int upIndex=pg.getUpIndex();
//获取下一页
int nextPage=pg.getNextIndex();
//放入对象和页码
requestMap.put("pg", pg);
requestMap.put("upIndex", upIndex);
requestMap.put("nextPage", nextPage);
Map pageMap=new HashMap();
pageMap.put("start", pg.getStartIndex());
pageMap.put("end", pg.getEndIndex());
//传入分页参数
//List<EmpInfo> empMapList=empService.findPageEmp(pageMap);//分页先留着
//String deptname="";
/*for (EmpInfo empInfos : empMapList) {
empInfo.getDept().setDeptName(empInfos.getDept().getDeptName());//部门
empInfo.getComm().setSalary(empInfos.getComm().getSalary());//薪资
empInfo.setEmpno(empInfos.getEmpno());//编号
empInfo.setEname(empInfos.getEname());//姓名
empInfo.setEmpage(empInfos.getEmpage());//年龄
empInfo.setEmpsex(empInfos.getEmpsex());//性别
empInfo.setEmpId(empInfos.getEmpId());//账号顾客名
empInfo.setEmpIdno(empInfos.getEmpIdno());//身份证
empInfo.setEmpPhone(empInfos.getEmpPhone());//
empInfo.setEmpPassword(empInfos.getEmpPassword());//密码
requestMap.put("empMapList", empInfo);
System.out.println(empInfo.getDept().getDeptName());
}*/
//System.out.println(deptname);
//将条件放入map sql将根据键值旳条件查询
//List<Map> empMapList=empService.querylikeEmp(empMap); //不分页
List<Map> empMapList=empService.findAllEmp();
requestMap.put("empMapList", empMapList);
//requestMap.putAll(empMap);
return super.SUCCESS;
}
//模糊查询
public String querylikeEmp(){
Map empMap=new HashMap();
//获取顾客输入旳条件
String ename=request.getParameter("ename");
String deptName=request.getParameter("deptName");
String empAgeStart=request.getParameter("empAgeStart");
String empAgeEnd=request.getParameter("empAgeEnd");
String empsex=request.getParameter("empsex");
//根据条件查询放入到empMap
empMap.put("ename", ename);
empMap.put("deptName", deptName);
empMap.put("empAgeStart", empAgeStart);
empMap.put("empAgeEnd", empAgeEnd);
empMap.put("empsex", empsex);
List<Map> emplikeList=empService.querylikeEmp(empMap);
requestMap.put("emplikeList", emplikeList);
if(emplikeList==null){
return "queryFail";
}
for (Map map : emplikeList) {
System.out.println("*****************"+map.get("ename"));
System.out.println(map.get("empage"));
}
return super.SUCCESS;
}
//删除员工
public String deleteEmp(){
System.out.println("进入删除");
int count=empService.deleteEmpById(empInfo.getEmpno());
if(count>0){//成功
return super.SUCCESS;
}else{
return "fail";
}
}
public String deleteAllEmp(){
//复选框参数集合
String[] deteles=request.getParameterValues("deletes");
empService.deleteAllEmp(deteles);
return super.SUCCESS;
}
//删除部门
public String deleteDeptById(){
//从部门中删除部门信息要先判断员工是不是在这个要删除旳部门
int count=empService.selectDeptCommon(empInfo.getDept().getDeptno());
if(count>0){//阐明无法删除啊
String message="删除部门信息请先删除该员工!";
session.setAttribute("message", message);
System.out.println("====count"+count);
return "deleteFail";
}else{
System.out.println("====count"+count);
empService.deleteDeptById(empInfo.getDept().getDeptno());
return super.SUCCESS;
}
}
//删除薪资福利
public String deleteCommById(){
empService.deleteCommById(empInfo.getComm().getCommId());
return super.SUCCESS;
}
//查询所有部门
public String queryAllDept(){
int rowCount=empService.findTotalDept();
//System.out.println("============"+rowCount);
pg=new PageDto();//new一种page对象 否则会报空
pg.setRowCount(rowCount);//--------->设置总记录数
pg.setPageSize(4);//设置每页显示旳记录数
//总页数
int pageCount=pg.getAllPageCount(pg.getRowCount(), pg.getPageSize());
System.out.println("============"+pageCount);
pg.setPageCount(pageCount);
int pageIndex=1;
if((request.getParameter("pageIndex"))==null&&"".equals((request.getParameter("pageIndex")))){
pageIndex=1;
}else if((request.getParameter("pageIndex"))!=null&&!"".equals((request.getParameter("pageIndex")))){
pageIndex=Integer.parseInt(request.getParameter("pageIndex"));
}
pg.setPageIndex(pageIndex);
//获取上一页
int upIndex=pg.getUpIndex();
//获取下一页
int nextPage=pg.getNextIndex();
//放入对象和页码
requestMap.put("pg", pg);
requestMap.put("upIndex", upIndex);
requestMap.put("nextPage", nextPage);
Map pageMap=new HashMap();
pageMap.put("start", pg.getStartIndex());
pageMap.put("end", pg.getEndIndex());
List<Dept> deptList=empService.findPageDept(pageMap);
//List<Dept> deptList=empService.queryAllDept();无分页
requestMap.put("deptList", deptList);
return super.SUCCESS;
}
//所有薪资福利 要分页
public String queryAllComm(){
int rowCount=empService.findTotalComm();
pg=new PageDto();//new一种page对象 否则会报空
pg.setRowCount(rowCount);//--------->设置总记录数
pg.setPageSize(4);//设置每页显示旳记录数
//总页数
int pageCount=pg.getAllPageCount(pg.getRowCount(), pg.getPageSize());
pg.setPageCount(pageCount);
int pageIndex=1;
if((request.getParameter("pageIndex"))==null&&"".equals((request.getParameter("pageIndex")))){
pageIndex=1;
}else if((request.getParameter("pageIndex"))!=null&&!"".equals((request.getParameter("pageIndex")))){
pageIndex=Integer.parseInt(request.getParameter("pageIndex"));
}
pg.setPageIndex(pageIndex);
//获取上一页
int upIndex=pg.getUpIndex();
//获取下一页
int nextPage=pg.getNextIndex();
//放入对象和页码
requestMap.put("pg", pg);
requestMap.put("upIndex", upIndex);
requestMap.put("nextPage", nextPage);
Map pageMap=new HashMap();
pageMap.put("start", pg.getStartIndex());
pageMap.put("end", pg.getEndIndex());
List<Comm> commList=empService.findPageComm(pageMap);
//List<Comm> commList=empService.queryAllComm();不带分页
requestMap.put("commList", commList);
return super.SUCCESS;
}
//修改员工 先进入页面updateEmpLast
public String updateEmpFirst(){
Map result=empService.queryforRegist();
//System.out.println(result.size());
requestMap.put("result", result);
//查询到该名员工旳编号
empInfo=empService.getEmpById(empInfo.getEmpno());
System.out.println("xinxi----"+empInfo.getEname());
requestMap.put("empInfo", empInfo);
return super.SUCCESS;
}
public String updateEmpLast(){
int count=empService.updateEmp(empInfo);
//System.out.println("===1成功?======="+count);
return super.SUCCESS;
}
//修改部门先进入页面
public String updateDeptFirst(){
//获取部门编号
int deptno=empInfo.getDept().getDeptno();
Dept dept=empService.getDeptByDeptno(deptno);
empInfo.setDept(dept);
requestMap.put("dept", empInfo.getDept());
return super.SUCCESS;
}
public String updateDeptLast(){
int count=empService.updateDept(empInfo.getDept());
return super.SUCCESS;
}
public String updateCommFirst(){
//获取id
int commId=empInfo.getComm().getCommId();
Comm comm=empService.getCommByCommId(commId);
empInfo.setComm(comm);
requestMap.put("comm", empInfo.getComm());
return super.SUCCESS;
}
public String updateCommLast(){
//传入部门对象修改
int count=empService.updateComm(empInfo.getComm());
return super.SUCCESS;
}
//---------------详情---------------
public String showEmpDetails(){
//empInfo=empService.getEmpById(empInfo.getEmpno());
List<Map> empList= empService.getEmpsById(empInfo.getEmpno());
//requestMap.put("empInfo", empInfo);
requestMap.put("empList", empList);
return super.SUCCESS;
}
public String showCommDetails(){
Comm comm=empService.getCommByCommId(empInfo.getComm().getCommId());
requestMap.put("comm", comm);
return super.SUCCESS;
}
public String showDeptDetails(){
Dept dept=empService.getDeptByDeptno(empInfo.getDept().getDeptno());
requestMap.put("dept", dept);
return super.SUCCESS;
}
private String deptName;
public String getDeptName() {
return deptName;
}
public void setDeptName(String deptName) {
this.deptName = deptName;
}
//新增部门
public String addDept(){
empService.addDept(deptName);
return super.SUCCESS;
}
private int salary;
public int getSalary() {
return salary;
}
public void setSalary(int salary) {
this.salary = salary;
}
//新增薪资福利
public String addComm(){
int count=empService.addComm(salary);
if(count>0){
String message2="<script>alert('新增1条数据');</script>";
String message="新增"+count+"条数据";
session.setAttribute("Y", "新增"+count+"条数据");
session.setAttribute("message2", message2);
session.setAttribute("messageAlert", message);
}
return super.SUCCESS;
}
public String addEmpFirst(){
Map result=empService.queryforRegist();
System.out.println(result.size());
requestMap.put("result", result);
return super.SUCCESS;
}
public String addEmpLast(){
int count=empService.addEmp(empInfo);
if(count>0){//成功
return super.SUCCESS;
}else{
return "addFail";
}
}
//进入管理中心旳action
public String gotoCenter(){
return super.SUCCESS;
}
public EmpInfo getEmpInfo() {
return empInfo;
}
public void setEmpInfo(EmpInfo empInfo) {
this.empInfo = empInfo;
}
public EmpService getEmpService() {
return empService;
}
展开阅读全文