前述
这个周一直在逐步地完成临摹一个CRM系统的工作,并且每一小版本的工作都通过SVN记录下来。这个周初步了解学习了linux系统,选用的版本是Centos6.5,并且学会了搭建JavaEE所需要的环境,包括Tomcat7、jdk1.7、eclise,svn等基本环境。还学会了如何通过SSH远程登录服务器,如何在windows和linux之间交换数据。
小项目:CRM
练习步骤
1.确定需求
1.1登录 (基本流程、登录拦截器、校验)
1.2员工管理
- 查询所有
- 添加(ajax级联)
- 更新(标签回显)
- 条件查询
1.3课程类别 - 查询所有(条件 + 分页)
- 添加或更新
2.根据需求创建ER图,并在数据库中添加数据
3.在Eclips中创建CRM项目,并且将项目添加SVN版本控制器。
4.添加Spring、Hibernate、struts2等相关的jar包
5.对应ER图,创建相应的JavaBean,并且为相应的Bean添加hibernate配置文件。
<hibernate-mapping>
<class name="com.jessyon.crm.classes.domain.CrmClass" table="crm_class">
<id name="classId">
<generator class="uuid"></generator>
</id>
<property name="name"></property>
<property name="beginTime">
<column name="beginTime" sql-type="datetime"></column>
</property>
<property name="endTime">
<column name="endTime" sql-type="datetime"></column>
</property>
<property name="status"></property>
<property name="totalCount"></property>
<property name="upgradeCount"></property>
<property name="changeCount"></property>
<property name="runoffCount"></property>
<property name="remark"></property>
<property name="uploadTime">
<column name="uploadTime" sql-type="datetime"></column>
</property>
<property name="uploadPath"></property>
<property name="uploadFilename"></property>
<many-to-one name="courseType" class="com.jessyon.crm.coursetype.domain.CrmCourseType" column="courseTypeId"></many-to-one>
</class>
</hibernate-mapping>
6.配置spring
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<!-- 配置公共项 -->
<!-- 1 加载properties文件 -->
<context:property-placeholder location="classpath:jdbcInfo.properties"/>
<!-- 2 配置数据源 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="${jdbc.driverClass}"></property>
<property name="jdbcUrl" value="${jdbc.jdbcUrl}"></property>
<property name="user" value="${jdbc.user}"></property>
<property name="password" value="${jdbc.password}"></property>
</bean>
<!-- 3 session工厂 -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
<prop key="hibernate.current_session_context_class">thread</prop>
<prop key="javax.persistence.validation.mode">none</prop>
</props>
</property>
<property name="mappingLocations" value="classpath:com/jessyon/crm/*/domain/*.hbx.xml"></property>
<!-- 4 事务管理 -->
<!-- 4.1 事务管理器 -->
<bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<!-- 4.2 事务详情 -->
<tx:advice id="txAdvice" transaction-manager="txManager">
<tx:attributes>
<tx:method name="add*"/>
<tx:method name="save*"/>
<tx:method name="update*"/>
<tx:method name="delete*"/>
<tx:method name="find*" read-only="true"/>
<tx:method name="*" read-only="true"/>
</tx:attributes>
</tx:advice>
<!-- 4.3 aop编程
-->
<aop:config proxy-target-class="true">
<aop:advisor advice-ref="txAdvice" pointcut="execution(* com.jessyon.crm.*.service..*.*(..))"/>
</aop:config>
<!-- 包含其他子模块 -->
<!-- 员工 ,部门, 职务-->
<!-- <import resource="applicationContext-staff.xml"/>
<import resource="applicationContext-department.xml"/>
<import resource="applicationContext-post.xml"/>
<import resource="applicationContext-coursetype.xml"/> -->
</beans>
applicationContext-courseType.xml
其他的相关的配置文件,比如department、post、staff的配置文件都是以下格式
<bean id="courseTypeDao" class="com.jessyon.crm.coursetype.dao.impl.CourseTypeDaoImpl">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<!-- service -->
<bean id="courseTypeService" class="com.jessyon.crm.coursetype.service.impl.CourseTypeServiceImpl">
<property name="courseTypeDao" ref="courseTypeDao"></property>
</bean>
7.配置struts2
<?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>
<!-- 常量 -->
<constant name="struts.devMode" value="true"></constant>
<constant name="struts.ui.theme" value="simple"></constant>
<!-- 公共项 其他子模块都会继承common -->
<package name="common" namespace="/" extends="struts-default">
<!-- 配置拦截器 -->
<interceptors>
<interceptor name="loginInterceptor" class="com.jessyon.crm.web.interceptor.LoginInterceptor"></interceptor>
<interceptor-stack name="loginStack">
<interceptor-ref name="defaultStack"></interceptor-ref>
<interceptor-ref name="loginInterceptor">
<!-- 不需要拦截的方法,多个方法逗号隔开 -->
<param name="excludeMethods">login</param>
</interceptor-ref>
</interceptor-stack>
</interceptors>
<!-- <default-interceptor-ref name="loginStack"></default-interceptor-ref> -->
<global-results>
<result name="login">/WEB-INF/pages/login.jsp</result>
</global-results>
<action name="uiAction_*_*">
<result>/WEB-INF/pages/{1}/{2}.jsp</result>
</action>
</package>
<!-- 包含其他子模块 -->
<include file="struts/struts-staff.xml"></include>
<include file="struts/struts-post.xml"></include>
<include file="struts/struts-department.xml"></include>
<include file="struts/struts-coursetype.xml"></include>
</struts>
struts2-courseType.xml
其他的相关的配置文件,比如department、post、staff的配置文件都是以下格式
<?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>
<package name="coursetype" namespace="/" extends="common">
<action name="courseTypeAction_*" class="com.jessyon.crm.coursetype.web.action.CourseTypeAction" method="{1}">
<result name="findAll">/WEB-INF/pages/coursetype/listCourse.jsp</result>
<result name="saveOrUpdateUI">/WEB-INF/pages/coursetype/addOrEditCourse.jsp</result>
<result name="saveOrUpdate" type="redirectAction">
<param name="namespace">/</param>
<param name="actionName">courseTypeAction_findAll</param>
</result>
</action>
</package>
</struts>
8.配置web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>Mycrm</display-name>
<filter>
<filter-name>openSession</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>openSession</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/applicationContext*.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<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>
</web-app>