1. 程式人生 > >Activiti(六)SSH專案實戰

Activiti(六)SSH專案實戰

1.1 建立專案

這裡寫圖片描述

1.2 新增Jar包

這裡寫圖片描述
1.3 更改配置檔案

1.3.1 連線資料庫

這裡寫圖片描述
1.3.2 Spring檔案的配置

這裡寫圖片描述

2 專案配置

applicationContext-dao.xml

<bean id="employeeDao" class="cn.itcast.ssh.dao.impl.EmployeeDaoImpl" parent="baseDao">
</bean>

<bean id="leaveBillDao" class="cn.itcast.ssh.dao.impl.LeaveBillDaoImpl" parent="baseDao"
>
</bean>

這裡說明一下:
parent=”baseDao”等同於

<bean id="baseDao" abstract="true">
<propertyname="sessionFactory"ref="sessionFactory"></property>
</bean>

這裡寫圖片描述

applicationContext-service.xml

    <bean id="employeeService" class="cn.itcast.ssh.service.impl.EmployeeServiceImpl"
>
<property name="employeeDao" ref="employeeDao"></property> <!-- 員工--> </bean> <bean id="leaveBillService" class="cn.itcast.ssh.service.impl.LeaveBillServiceImpl"> <property name="leaveBillDao" ref="leaveBillDao"></property> <!-- 請假單-->
</bean> <bean id="workflowService" class="cn.itcast.ssh.service.impl.WorkflowServiceImpl"> <property name="repositoryService" ref="repositoryService"></property> <property name="runtimeService" ref="runtimeService"></property> <property name="taskService" ref="taskService"></property> <property name="formService" ref="formService"></property> <property name="historyService" ref="historyService"></property> <property name="leaveBillDao" ref="leaveBillDao"></property> </bean>

這裡寫圖片描述

applicationContext-action.xml

<bean id="loginAction" class="cn.itcast.ssh.web.action.LoginAction" scope="prototype">
<property name="employeeService" ref="employeeService"></property>
</bean>
<bean id="leaveBillAction" class="cn.itcast.ssh.web.action.LeaveBillAction" scope="prototype">
<property name="leaveBillService" ref="leaveBillService"></property>
</bean>
<bean id="workflowAction" class="cn.itcast.ssh.web.action.WorkflowAction" scope="prototype"><!--MVC預設是單例,改為多例-->
<property name="workflowService" ref="workflowService"></property>
<property name="leaveBillService" ref="leaveBillService"></property>
</bean>

這裡寫圖片描述

activiti-context.xml,配置activiti表和事物以及service 不用建立流程引擎 直接引入就可以

<!-- spring負責建立流程引擎的配置檔案 -->
<bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">
<!-- 資料來源 -->
<property name="dataSource" ref="dataSource" />
<!-- 配置事務管理器,統一事務 -->
<property name="transactionManager" ref="transManager" />
<!-- 設定建表策略,如果沒有表,自動建立表 -->
<property name="databaseSchemaUpdate" value="true" />
</bean>
<!-- 建立流程引擎物件 -->
<bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean">
<property name="processEngineConfiguration" ref="processEngineConfiguration" />
</bean>

<!-- 
相當於下面的程式碼
RepositoryServicie repositoryService = processEngine.getRepositoryService();
RuntimeServicie repositoryService = processEngine.getRuntimeServicie();
TaskServicie taskServicie = processEngine.getTaskServicie();
HistoryServicie historyServicie = processEngine.getHistoryServicie();
 -->
<!-- 由流程引擎物件,提供的方法,建立專案中使用的Activiti工作流的Service -->
<!--靜態注入 定義processEngine可以點出來service
-->
<bean id="repositoryService" factory-bean="processEngine" factory-method="getRepositoryService" />
<bean id="runtimeService" factory-bean="processEngine" factory-method="getRuntimeService" />
<bean id="taskService" factory-bean="processEngine" factory-method="getTaskService" />
<bean id="historyService" factory-bean="processEngine" factory-method="getHistoryService" />
<bean id="formService" factory-bean="processEngine" factory-method="getFormService" />

struts的配置

<struts>
    <!-- 配置模式為開發模式,自動載入struts.xml和顯示錯誤提示資訊 -->
    <constant name="struts.devMode" value="true" />
    <!-- 設定頁面主題為簡單主題,去掉struts2開發提供的樣式 -->
    <constant name="struts.ui.theme" value="simple" />

    <package name="default" namespace="/" extends="struts-default">
    <!-- 攔截器配置 -->
    <interceptors>
    <!-- 定義了一個用於攔截器登入的攔截器 -->
    <interceptor name="loginInterceptor" class="cn.itcast.ssh.utils.LoginInteceptor"></interceptor>
    <!-- 定義一個攔截器棧 -->
    <interceptor-stack name="systemStack">
    <interceptor-ref name="defaultStack" />
    <interceptor-ref name="loginInterceptor" />
</interceptor-stack>
    </interceptors>

  <!-- 定義系統預設攔截器 全域性 -->
<default-interceptor-ref name="systemStack" /> 
    <!-- 全域性結果檢視 -->
    <global-results>
    <result name="login" type="redirect">
    login.jsp
    </result>
    </global-results>

    <action name="loginAction_*" class="loginAction" method="{1}">
        <result name="success">WEB-INF/views/main.jsp</result>
        <result name="top">WEB-INF/views/top.jsp</result>
        <result name="left">WEB-INF/views/left.jsp</result>
        <result name="welcome">WEB-INF/views/welcome.jsp</result>
        </action>

        <action name="leaveBillAction_*" class="leaveBillAction" method="{1}">
            <result name="home">WEB-INF/views/leaveBill/list.jsp</result>
            <result name="input">WEB-INF/views/leaveBill/input.jsp</result>
            <result name="save" type="redirectAction">
        <param name="actionName">leaveBillAction_home.action</param>
        </result>
        </action>

    <action name="workflowAction_*" class="workflowAction" method="{1}">
        <result name="list" type="redirectAction">
        <param name="actionName">workflowAction_deployHome.action</param>
        </result>
        <result name="deployHome">WEB-INF/views/workflow/workflow.jsp</result>
        <result name="task">WEB-INF/views/workflow/task.jsp</result>
        <result name="image">WEB-INF/views/workflow/image.jsp</result>
        <result name="listTask" type="redirectAction">
    <param name="actionName">workflowAction_listTask.action</param>
            </result>
        <result name="viewTaskForm" type="redirectAction">
        <param name="actionName">/workflowAction_audit.action</param>
        </result>
        <result name="taskForm">WEB-INF/views/workflow/taskForm.jsp</result>
            <result name="viewHisComment">WEB-INF/views/workflow/taskFormHis.jsp</result>
        </action>
    </package>
</struts>

這裡寫圖片描述

配置資料庫表

這裡寫圖片描述

這裡寫圖片描述

3 流程圖

這裡寫圖片描述