1、基本的环境
1.1、开发工具:Myeclipse 2017 CI
1.2、struts2:struts-2.3.34
1.3、hibernate:hibernate-release-5.2.10.Final
1.4、tomcat: apache-tomcat-8.5.15
1.5、mysql驱动:mysql-connector-java-5.1.42-bin
1.7、C3P0数据源
1.8、数据库MYSQL5.1以上
2、搭建基本strust2运行环境
2.1、配置web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
<filter>
<filter-name>Struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>Struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
2.2、在src目录下创建strust.xml文件(这个是最终的strust.xml)
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<bean name="employeeDao" type="com.splend.crud.dao.EmployeeDao"
class="com.splend.crud.dao.EmployeeDaoImpl"></bean>
<bean name="employeeService" type="com.splend.crud.service.EmployeeService"
class="com.splend.crud.service.EmployeeServiceImpl"></bean>
<!-- Overwrite Convention -->
<package name="default" extends="struts-default" namespace="/">
<interceptors>
<interceptor-stack name="splend">
<interceptor-ref name="paramsPrepareParamsStack">
<param name="prepare.alwaysInvokePrepare">false</param>
</interceptor-ref>
</interceptor-stack>
</interceptors>
<default-interceptor-ref name="splend"></default-interceptor-ref>
<action name="emp-*" class="com.splend.crud.handler.EmployeeAction"
method="{1}">
<result name="success" type="redirectAction">emp-list</result>
<result name="{1}">/emp-{1}.jsp</result>
</action>
<action name="test" class="com.splend.crud.handler.HelloWorld">
<result name="success">/success.jsp</result>
</action>
</package>
</struts>
3、用hibernate编写dao层
3.1、写一个Employee的javabean
package com.splend.crud.entity;
public class Employee {
private Integer employeeId;
private String firstName;
private String lastName;
private String email;
public Employee() {
}
public Employee(Integer employeeId, String firstName, String lastName, String email) {
super();
this.employeeId = employeeId;
this.firstName = firstName;
this.lastName = lastName;
this.email = email;
}
public Integer getEmployeeId() {
return employeeId;
}
public void setEmployeeId(Integer employeeId) {
this.employeeId = employeeId;