package com.zl.entity;
import java.util.Date;
/**
* Emp entity.
*
* @author MyEclipse Persistence Tools
*/
public class Emp implements java.io.Serializable {
// Fields
private Long empno;
private String ename;
private String job;
private Long mgr;
private Date hiredate;
private Double sal;
private Double comm;
// Constructors
/** default constructor */
public Emp() {
}
// Property accessors
public Long getEmpno() {
return this.empno;
}
public void setEmpno(Long empno) {
this.empno = empno;
}
public String getEname() {
return this.ename;
}
public void setEname(String ename) {
this.ename = ename;
}
public String getJob() {
return this.job;
}
public void setJob(String job) {
this.job = job;
}
public Long getMgr() {
return this.mgr;
}
public void setMgr(Long mgr) {
this.mgr = mgr;
}
public Date getHiredate() {
return this.hiredate;
}
public void setHiredate(Date hiredate) {
this.hiredate = hiredate;
}
public Double getSal() {
return this.sal;
}
public void setSal(Double sal) {
this.sal = sal;
}
public Double getComm() {
return this.comm;
}
public void setComm(Double comm) {
this.comm = comm;
}
}
package com.zl.entity;
public class User {
private int id;
private String userName;
private String pwd;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getPwd() {
return pwd;
}
public void setPwd(String pwd) {
this.pwd = pwd;
}
}
package com.zl.dao;
import java.util.List;
import com.zl.entity.Emp;
public interface EmpDao {
public void addEmp(Emp e);
public void updateEmpByEmpNo(int empNo);
public void deleteEmpByEmpNo(int empNo);
public List<Emp> selectAll();
}
package com.zl.dao.impl;
import java.sql.SQLException;
import java.util.List;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;
import com.zl.dao.EmpDao;
import com.zl.entity.Emp;
public class EmpDaoImpl extends SqlMapClientDaoSupport implements EmpDao {
public void addEmp(Emp e) {
}
public void deleteEmpByEmpNo(int empNo) {
}
public List<Emp> selectAll() {
List<Emp> list=null;
try {
list=this.getSqlMapClient().queryForList("selectAllEmp");
} catch (SQLException e) {
e.printStackTrace();
}
return list;
}
public void updateEmpByEmpNo(int empNo) {
}
}
package com.zl.biz;
import java.util.List;
import com.zl.entity.Emp;
public interface EmpBiz {
public void addEmp(Emp e);
public void updateEmpByEmpNo(int empNo);
public void deleteEmpByEmpNo(int empNo);
public List<Emp> selectAll();
}
package com.zl.biz.impl;
import java.util.List;
import com.zl.biz.EmpBiz;
import com.zl.dao.EmpDao;
import com.zl.entity.Emp;
public class EmpBizImpl implements EmpBiz{
private EmpDao empdao;
public void setEmpdao(EmpDao empdao) {
this.empdao = empdao;
}
public void addEmp(Emp e) {
// TODO Auto-generated method stub
}
public void deleteEmpByEmpNo(int empNo) {
// TODO Auto-generated method stub
}
public List<Emp> selectAll() {
return empdao.selectAll();
}
public void updateEmpByEmpNo(int empNo) {
// TODO Auto-generated method stub
}
}
package com.zl.action;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;
import com.zl.biz.EmpBiz;
import com.zl.entity.Emp;
public class EmpAction extends DispatchAction {
private EmpBiz empbiz;
public void setEmpbiz(EmpBiz empbiz) {
this.empbiz = empbiz;
}
public ActionForward show(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
List<Emp> listemp=empbiz.selectAll();
request.setAttribute("listemp", listemp);
return mapping.findForward("index");
}
}
package com.zl.form;
import org.apache.struts.action.ActionForm;
import com.zl.entity.Emp;
public class EmpForm extends ActionForm{
private Emp emp=new Emp();
public Emp getEmp() {
return emp;
}
public void setEmp(Emp emp) {
this.emp = emp;
}
}
applicationContext-dao.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<!-- dao -->
<bean id="empdao" class="com.zl.dao.impl.EmpDaoImpl">
<property name="sqlMapClient" ref="sqlMapClient"></property>
</bean>
</beans>
applicationContext-biz.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<bean id="empbiz" class="com.zl.biz.impl.EmpBizImpl">
<property name="empdao" ref="empdao"></property>
</bean>
</beans>
applicationContext-action.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<bean name="/empdodo" class="com.zl.action.EmpAction">
<property name="empbiz" ref="empbiz" ></property>
</bean>
</beans>
applicationContext-common.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<!-- bean -->
<bean id="PropertyPlaceholder" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:oracle.properties</value>
</list>
</property>
</bean>
<!-- datasourse -->
<bean id="datasource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="${driver}">
</property>
<property name="url" value="${url}"></property>
<property name="username" value="${username}"></property>
<property name="password" value="${password}"></property>
</bean>
<!-- sqlmapCient -->
<bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="configLocation" value="classpath:SqlMapConfig.xml"></property>
<property name="dataSource" ref="datasource" ></property>
</bean>
</beans>
Emp.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE sqlMap
PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"
"http://ibatis.apache.org/dtd/sql-map-2.dtd">
<sqlMap >
<typeAlias alias="Emp" type="com.zl.entity.Emp"/>
<select id="selectAllEmp" resultClass="Emp" >
select * from emp
</select>
<!--
<insert id="insertEmp" parameterClass="Emp">
<selectKey resultClass="int" keyProperty="empno">
select empSequence.nextVal from dual
</selectKey>
insert into emp(empno,ename,job,mgr,hiredate,sal,comm,deptno) values(#empno#,#ename#,#job#,#mgr#,#hiredate#,#sal#,#comm#,#deptno#)
</insert>-->
</sqlMap>
oracle.properties:
driver=oracle.jdbc.driver.OracleDriver
url=jdbc:oracle:thin:@localhost:1521:orcl
username=hello
password=123
SqlMapConfig.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE sqlMapConfig
PUBLIC "-//ibatis.apache.org//DTD SQL Map Config 2.0//EN"
"http://ibatis.apache.org/dtd/sql-map-config-2.dtd">
<sqlMapConfig>
<!--
<transactionManager type="JDBC" commitRequired="false">
<dataSource type="SIMPLE">
<property name="JDBC.Driver" value="com.mysql.jdbc.Driver" />
<property name="JDBC.ConnectionURL"
value="jdbc:mysql://127.0.0.1:3306/ibatis" />
<property name="JDBC.Username" value="root" />
<property name="JDBC.Password" value="ok" />
</dataSource>
</transactionManager>-->
<!-- 指定实体映射文件的路径 -->
<sqlMap resource="Emp.xml" />
<sqlMap resource="user.xml"/>
</sqlMapConfig>
user.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE sqlMap
PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"
"http://ibatis.apache.org/dtd/sql-map-2.dtd">
<sqlMap >
<typeAlias alias="user" type="com.zl.entity.User"/>
<select id="selectAllUser" resultClass="user" >
select * from userE
</select>
</sqlMap>
web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.4" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext-*.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>3</param-value>
</init-param>
<init-param>
<param-name>detail</param-name>
<param-value>3</param-value>
</init-param>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
add.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>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<center><h1>添加员工</h1>
<form action="" method="post">
员工名称:<input type="text" name=""><br>
员工工作:<input type="text" name=""><br>
员工上级:<input type="text" name=""><br>
入职时间:<input type="text" name=""><br>
员工薪水:<input type="text" name=""><br>
额外薪水:<input type="text" name=""><br>
<input type="submit" value="提交"><br>
</form>
</center>
</body>
</html>
index.jsp:
<%@ page language="java" isELIgnored="false" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<%@taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%
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>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!-- contentType="application/vnd.ms-excel" -->
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<jsp:include page="/empdo.do?method=show" />
</head>
<body>
<center><h1>员工管理</h1>
<table border="1">
<tr>
<td>员工编号</td>
<td>员工名称</td>
<td>员工工作</td>
<td>员工上级</td>
<td>入职时间</td>
<td>员工薪水</td>
<td>额外薪水</td>
<td>操作</td>
</tr>
<logic:iterate id="e" name="listemp">
<tr>
<td>${e.empno}</td>
<td>${e.ename }</td>
<td>${e.job }</td>
<td>${e.mgr }</td>
<td><bean:write name="e" property="hiredate" format="yyyy年MM月dd日 hh:mm:ss"/> </td>
<td>${e.sal} </td>
<td>${e.comm} </td>
<td><a href="add.jsp">添加</a>/<a href="#">删除</a>/<a href="#">修改</a></td>
</tr>
</logic:iterate>
</table>
</center>
</body>
</html>