SSM框架项目实例源代码从注册开始结合数据库.docx_第1页
SSM框架项目实例源代码从注册开始结合数据库.docx_第2页
SSM框架项目实例源代码从注册开始结合数据库.docx_第3页
SSM框架项目实例源代码从注册开始结合数据库.docx_第4页
SSM框架项目实例源代码从注册开始结合数据库.docx_第5页
已阅读5页,还剩85页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

/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/ENhtml head base href=%=basePath% title入口页面/titlemeta http-equiv=pragma content=no-cachemeta http-equiv=cache-control content=no-cachemeta http-equiv=expires content=0 meta http-equiv=keywords content=keyword1,keyword2,keyword3meta http-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=leftdiva href=common/login.jsp登录/a/div div id=rightdiva href=toRegist.action注册/a/div /div /body/html/SSM/src/config/applicationContext.xml?xml version=1.0 encoding=UTF-8?beansxmlns=/schema/beansxmlns:xsi=/2001/XMLSchema-instancexmlns:p=/schema/pxsi:schemaLocation=/schema/beans /schema/beans/spring-beans-3.0.xsd!- 添加数据源 BasicDataSource -bean id=dataSource class=mons.dbcp.BasicDataSourceproperty 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/propertyproperty name=sqlSessionFactory ref=sessionFactory/property/bean!- 配置业务逻辑层 给属性注入数据层的dao对象-bean id=empService class=.impl.EmpServiceImplproperty 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.javaproperty name=empService ref=empService/property/bean/beans/SSMEXAM/src/com/action/EmpAction.javapackage com.action;import java.util.HashMap;import java.util.List;import java.util.Map;import .EmpService;import mon.action.BaseAction;import mon.dto.Comm;import mon.dto.Dept;import mon.dto.EmpInfo;import mon.dto.PageDto;/* * 控制层 * author Administrator * */public class EmpAction extends BaseActionprivate EmpService empService;private EmpInfo empInfo;private PageDto pg;public String toRegist()Map result=empService.queryforRegist();requestMap.put(result, result);return super.SUCCESS;/注册的actionpublic String register()int counts=empService.queryEmpByName(empInfo.getEname();if(counts0)/说明该注册名是存在的 return registerFail;elseint count=empService.addEmp(empInfo);System.out.println(新增了+count+条数据);if(count!=0)return registerSuccess;elsereturn 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;elsereturn 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(count0)/说明存在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();/传入分页参数/ListEmpInfo 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将根据键值的条件查询/ListMap empMapList=empService.querylikeEmp(empMap); /不分页ListMap 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);/根据条件查询放入到empMapempMap.put(ename, ename);empMap.put(deptName, deptName);empMap.put(empAgeStart, empAgeStart);empMap.put(empAgeEnd, empAgeEnd);empMap.put(empsex, empsex);ListMap 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(count0)/成功return super.SUCCESS;elsereturn 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(count0)/说明无法删除啊String message=删除部门信息请先删除该员工!;session.setAttribute(message, message);System.out.println(=count+count);return deleteFail;elseSystem.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();ListDept deptList=empService.findPageDept(pageMap);/ListDept 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();ListComm commList=empService.findPageComm(pageMap);/ListComm commList=empService.queryAllComm();不带分页requestMap.put(commList, commList);return super.SUCCESS;/修改员工 先进入页面updateEmpLastpublic 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()/获取idint 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();ListMap 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 StringshowDeptDetails()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(count0)String message2=scriptalert(新增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(count0)/成功return super.SUCCESS;elsereturn 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;public void setEmpService(EmpService empService) this.empService = empService;/SSM/src/com/common/action/BaseAction.java继承的action类package mon.action;import java.util.Map;import javax.servlet.ServletContext;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import javax.servlet.http.HttpSession;import org.apache.struts2.ServletActionContext;import com.opensymphony.xwork2.ActionContext;import com.opensymphony.xwork2.ActionSupport;public class BaseAction extends ActionSupportprotected MapString,Object sessionMap;/session map集合的对象protected MapString,Object applicationMap;protected MapString,Object requestMap;protected HttpServletRequest request;/原生request的对象protected HttpServletResponse response;protected HttpSession session;protected ServletContext application;protected MapString,Object paramsMap;/参数map的集合SuppressWarnings(unchecked)public BaseAction()/构造方法/* * 通过ActionContext获得上下文 然后直接点获得session的方法 */sessionMap=ActionContext.getContext().getSession();applicationMap=ActionContext.getContext().getApplication();requestMap=(MapString,Object)ActionContext.getContext().get(request);request=(HttpServletRequest)ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);response=(HttpServletResponse)ActionContext.getContext().get(ServletActionContext.HTTP_RESPONSE);application=(ServletContext)ActionContext.getContext().get(ServletActionContext.SERVLET_CONTEXT);session=request.getSession();paramsMap=ActionContext.getContext().getParameters();/SSM/src/config/emp.xml?xml version=1.0 encoding=UTF-8?!DOCTYPE mapper PUBLIC -//DTD Mapper 3.0/EN /dtd/mybatis-3-mapper.dtd mapper namespace=com.dao.EmpDao!- 注册用查询该用户是否存在啊 验证的是用户名-select id=queryEmpByName resultType=int parameterType=mon.dto.EmpInfoselect count(*) from emp_info where empId=#empId/select!- 注册用 注册用户插入表格中 10个字段-insert id=addEmp parameterType=mon.dto.EmpInfo insert into emp_info values (seq_emp.nextval, #empId,#ename,#empage,#empsex,#empIdno,#empPhone,#empPassword,#dept.deptno,#mId)/insert!- *查询部分* -select id=findAllEmp resultType=java.util.Mapselect e.empno, e.empid,e.empname,e.empage, e.empsex,e.empidno ,e.empphone, e.emppassword, d.deptno,d.deptname,mid,c.salary from emp_info e,emp_dept d,emp_comm c where d.deptno=e.deptno and mid=mid/select!- 根据用户名查询 -select id=queryEmpByEname resultType=int parameterType=Stringselect count(*) from emp_info where empname=#ename /select!- 查到员工byidselect id=getEmpById resultType=mon

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论