关于SSH框架的完整配置

              SSH指的是SpringMVC   Spring    Hibernate     利用的是maven工具搭建的框架,及HIbernate的反向工程的使用


(一):pom.xml     其中包含fileupload的包,日志以及测试类的包(Tomcat8.5web容器支持的下载方式)

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.qf.ll</groupId>
  <artifactId>HRMS</artifactId>
  <packaging>war</packaging>
  <version>1.0.0</version>
  <name>HRMS Maven Webapp</name>
  <url>http://maven.apache.org</url>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.12</version>
      <scope>test</scope>
    </dependency>
    <dependency>
		<groupId>javax.servlet</groupId>
		<artifactId>javax.servlet-api</artifactId>
		<version>3.1.0</version>
		<scope>provided</scope>
	</dependency>
	<dependency>
		<groupId>javax.servlet.jsp</groupId>
		<artifactId>javax.servlet.jsp-api</artifactId>
		<version>2.3.2-b01</version>
		<scope>provided</scope>
	</dependency>	
	 <!-- jstl -->
	<dependency>
		<groupId>javax.servlet</groupId>
		<artifactId>jstl</artifactId>
		<version>1.2</version>
	</dependency>
	
	<dependency>
		<groupId>mysql</groupId>
		<artifactId>mysql-connector-java</artifactId>
		<version>5.1.34</version>
	</dependency>	
		<!-- 日志记录所需包 -->
		<dependency>
			<groupId>org.slf4j</groupId>
			<artifactId>slf4j-api</artifactId>
			<version>1.7.5</version>
		</dependency>
		<dependency>
			<groupId>org.slf4j</groupId>
			<artifactId>slf4j-log4j12</artifactId>
			<version>1.7.5</version>
			<scope>runtime</scope>
		</dependency>
		<dependency>
			<groupId>log4j</groupId>
			<artifactId>log4j</artifactId>
			<version>1.2.17</version>
			<scope>runtime</scope>
		</dependency>
		<dependency>
			<groupId>cglib</groupId>
			<artifactId>cglib</artifactId>
			<version>2.2.2</version>
		</dependency>
	<!-- hibernate -->
	<dependency>
		<groupId>org.hibernate</groupId>
		<artifactId>hibernate-core</artifactId>
		<version>5.2.10.Final</version>
	</dependency>

	<!-- for JPA, use hibernate-entitymanager instead of hibernate-core -->
	<dependency>
		<groupId>org.hibernate</groupId>
		<artifactId>hibernate-entitymanager</artifactId>
		<version>5.2.10.Final</version>
	</dependency>
	<!-- optional -->
	<dependency>
		<groupId>org.hibernate</groupId>
		<artifactId>hibernate-osgi</artifactId>
		<version>5.2.10.Final</version>
	</dependency>
	<dependency>
		<groupId>org.hibernate</groupId>
		<artifactId>hibernate-envers</artifactId>
		<version>5.2.10.Final</version>
	</dependency>
	<dependency>
		<groupId>org.hibernate</groupId>
		<artifactId>hibernate-c3p0</artifactId>
		<version>5.2.10.Final</version>
	</dependency>

	<dependency>
		<groupId>org.hibernate</groupId>
		<artifactId>hibernate-proxool</artifactId>
		<version>5.2.10.Final</version>
	</dependency>
	<dependency>
		<groupId>org.hibernate</groupId>
		<artifactId>hibernate-infinispan</artifactId>
		<version>5.2.10.Final</version>
	</dependency>
	<dependency>
		<groupId>org.hibernate</groupId>
		<artifactId>hibernate-ehcache</artifactId>
		<version>5.2.10.Final</version>
	</dependency>
	
	<dependency>
		<groupId>com.fasterxml.jackson.core</groupId>
		<artifactId>jackson-core</artifactId>
		<version>2.7.4</version>
	</dependency>
	<dependency>
		<groupId>com.fasterxml.jackson.core</groupId>
		<artifactId>jackson-databind</artifactId>
		<version>2.7.4</version>
	</dependency>		
	<dependency>
		<groupId>com.fasterxml.jackson.core</groupId>
		<artifactId>jackson-annotations</artifactId>
		<version>2.7.4</version>
	</dependency>
	
	<!-- 添加Spring包 -->
	<dependency>
		<groupId>org.springframework</groupId>
		<artifactId>spring-webmvc</artifactId>
		<version>4.3.6.RELEASE</version>
	</dependency> 
	
	<dependency>
		<groupId>org.springframework</groupId>
		<artifactId>spring-context</artifactId>
		<version>4.3.6.RELEASE</version>
	</dependency>
	<dependency>
		<groupId>org.springframework</groupId>
		<artifactId>spring-context-support</artifactId>
		<version>4.3.6.RELEASE</version>
	</dependency>
	<dependency>
		<groupId>org.springframework</groupId>
		<artifactId>spring-web</artifactId>
		<version>4.3.6.RELEASE</version>
	</dependency>
	<dependency>
		<groupId>org.springframework</groupId>
		<artifactId>spring-jdbc</artifactId>
		<version>4.3.6.RELEASE</version>
	</dependency>
	
	<!-- 为了方便进行单元测试,添加spring-test包 -->
	<dependency>
		<groupId>org.springframework</groupId>
		<artifactId>spring-test</artifactId>
		<version>4.3.6.RELEASE</version>
	</dependency>
	<dependency>
		<groupId>org.springframework</groupId>
		<artifactId>spring-aspects</artifactId>
		<version>4.3.6.RELEASE</version>
	</dependency>
	<dependency>
		<groupId>org.springframework</groupId>
		<artifactId>spring-expression</artifactId>
		<version>4.3.6.RELEASE</version>
	</dependency>
	<dependency>
		<groupId>org.springframework</groupId>
		<artifactId>spring-orm</artifactId>
		<version>4.3.6.RELEASE</version>
	</dependency>
	<!--添加aspectjweaver包 -->
	<dependency>
		<groupId>org.aspectj</groupId>
		<artifactId>aspectjweaver</artifactId>
		<version>1.8.5</version>
	</dependency>
	
	<dependency>
		<groupId>commons-fileupload</groupId>
		<artifactId>commons-fileupload</artifactId>
		<version>1.2.2</version>
	</dependency>
	<dependency>
		<groupId>commons-io</groupId>
		<artifactId>commons-io</artifactId>
		<version>2.0.1</version>
	</dependency>  
  </dependencies>
  <build>
    <finalName>HRMS</finalName>
    <plugins>
		<!-- 编译插件,指定编译用的的jdk版本 -->
		<plugin>
			<groupId>org.apache.maven.plugins</groupId>
			<artifactId>maven-compiler-plugin</artifactId>
			<configuration>
				<source>1.8</source>
				<target>1.8</target>
				<encoding>UTF-8</encoding>
			</configuration>
		</plugin>
	</plugins>  
  </build>
</project>
(二):applicationContext.xml在这个中,我们将dao层和service层的单独分开,利用import去引入,在action层我们利用了注解的形式

<?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"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xsi:schemaLocation="http://www.springframework.org/schema/beans 
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/aop
        http://www.springframework.org/schema/aop/spring-aop.xsd
        http://www.springframework.org/schema/tx
        http://www.springframework.org/schema/tx/spring-tx.xsd
        http://www.springframework.org/schema/context   
        http://www.springframework.org/schema/context/spring-context.xsd   
        http://www.springframework.org/schema/mvc   
        http://www.springframework.org/schema/mvc/spring-mvc.xsd">
        <!-- 位置c3p0  com.mchange.v2.c3p0      ComboPooledDataSource.class-->
        <!--  ctrl+o  两次-->
	<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
	<!-- 四个参数 -->
	<property name="driverClass" value="org.gjt.mm.mysql.Driver"></property>
	<!-- 持久层编码格式的设置 -->
	<property name="jdbcUrl" value="jdbc:mysql:///hrms?useUnicode=true&characterEncoding=utf8"></property>
	<property name="user" value="root"></property>
	<property name="password" value="root"></property>
	</bean>
	<!-- spring-orm  hibernate5   LocalSessionFactoryBean.class-->
	<bean id="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
	<property name="dataSource" ref="dataSource"></property>
	<!-- hibernate的属性格式 -->
	<property name="hibernateProperties">
	<props>
	<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
	<prop key="hibernate.format_sql">true</prop>
	<prop key="hibernate.show_sql">true</prop>
	</props>
	</property>
	<property name="mappingResources">
	<array>
	<!-- 注册实体 -->
	<value>com/qf/pojo/HrmsChannel.hbm.xml</value>
	<value>com/qf/pojo/HrmsChtype.hbm.xml</value>
	<value>com/qf/pojo/HrmsDemand.hbm.xml</value>
	<value>com/qf/pojo/HrmsDept.hbm.xml</value>
	<value>com/qf/pojo/HrmsInterview.hbm.xml</value>
	<value>com/qf/pojo/HrmsPrecontract.hbm.xml</value>
	<value>com/qf/pojo/HrmsProject.hbm.xml</value>
	<value>com/qf/pojo/HrmsResume.hbm.xml</value>
	<value>com/qf/pojo/HrmsStaff.hbm.xml</value>
	</array>
	</property>
	</bean>
	<import resource="service.xml"/>	
	<bean id="txManager" class="org.springframework.orm.hibernate5.HibernateTransactionManager">
	<property name="dataSource" ref="dataSource"></property>
	<property name="sessionFactory" ref="sessionFactory"></property>
	</bean>
	<tx:advice id="txadvice" transaction-manager="txManager">
	<tx:attributes>
	<tx:method name="add*" propagation="REQUIRED"/>
	<tx:method name="update*" propagation="REQUIRED"/>
	<tx:method name="del*" propagation="REQUIRED"/>
	<tx:method name="remove*" propagation="REQUIRED"/>
	<tx:method name="save*" propagation="REQUIRED"/>
	<tx:method name="get*" read-only="true"/>
	<tx:method name="find*" read-only="true"/>
	</tx:attributes>
	</tx:advice>
	<aop:config>
	<aop:pointcut expression="execution(* com.qf.service.*.*(..))" id="mypoint"/>
	<aop:advisor advice-ref="txadvice" pointcut-ref="mypoint"/>
	</aop:config>
	<context:component-scan base-package="com.qf.action"></context:component-scan>
		<mvc:annotation-driven></mvc:annotation-driven>
	<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"></bean>
	<!-- 文件上传的配置文件 -->
	<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
		<!-- 限定最大上传的大小 -->
		<property name="maxUploadSize" value="10240000"></property>
	</bean>
	<!-- 异常解析器 ,解析器是继承了Handle接口的那一个-->
	<bean class="com.qf.exception.HrmsExceptionErrPage"></bean>
<!-- 配置拦截器 -->
<mvc:interceptors>
   <mvc:interceptor>
         <mvc:mapping path="/**"/>
         <bean class="com.qf.login.LoginHandleInte"></bean>
   </mvc:interceptor>
</mvc:interceptors>
</beans>

(三)dao层的配置

<?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"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xsi:schemaLocation="http://www.springframework.org/schema/beans 
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/aop
        http://www.springframework.org/schema/aop/spring-aop.xsd
        http://www.springframework.org/schema/tx
        http://www.springframework.org/schema/tx/spring-tx.xsd
        http://www.springframework.org/schema/context   
        http://www.springframework.org/schema/context/spring-context.xsd   
        http://www.springframework.org/schema/mvc   
        http://www.springframework.org/schema/mvc/spring-mvc.xsd">
	<!-- 注册dao层 -->
	<bean id="hrmsDeptDao" class="com.qf.dao.HrmsDeptDaoImpl">
	  <property name="sessionFactory" ref="sessionFactory"></property>
	</bean>
	<bean id="hrmsProjectDao" class="com.qf.dao.HrmsProjectDaoImpl">
	<property name="sessionFactory" ref="sessionFactory"></property>
	</bean>
	<bean id="hrmsStaffDao" class="com.qf.dao.HrmsStaffDaoImpl">
	<property name="sessionFactory" ref="sessionFactory"></property>
	</bean>
	<bean id="hrmsResumeDao" class="com.qf.dao.HrmsResumeDaoImpl">
	<property name="sessionFactory" ref="sessionFactory"></property>
	</bean>
	<bean id="hrmsChtypeDao" class="com.qf.dao.HrmsChtypeDaoImpl">
	<property name="sessionFactory" ref="sessionFactory"></property>
	</bean>
	<bean id="hrmsChannelDao" class="com.qf.dao.HrmsChannelDaoImpl">
	<property name="sessionFactory" ref="sessionFactory"></property>
	</bean>
	
	<bean id="hrmsDemandDao" class="com.qf.dao.HrmsDemandDaoImpl">
	<property name="sessionFactory" ref="sessionFactory"></property>
	</bean>
	
	<bean id="hrmsPrecontractDao" class="com.qf.dao.HrmsPrecontractDaoImpl">
	<property name="sessionFactory" ref="sessionFactory"></property>
	</bean>
	
	<bean id="hrmsInterviewDao" class="com.qf.dao.HrmsInterviewDaoImpl">
	<property name="sessionFactory" ref="sessionFactory"></property>
	</bean>
</beans>

(四)service层的配置

<?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"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xsi:schemaLocation="http://www.springframework.org/schema/beans 
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/aop
        http://www.springframework.org/schema/aop/spring-aop.xsd
        http://www.springframework.org/schema/tx
        http://www.springframework.org/schema/tx/spring-tx.xsd
        http://www.springframework.org/schema/context   
        http://www.springframework.org/schema/context/spring-context.xsd   
        http://www.springframework.org/schema/mvc   
        http://www.springframework.org/schema/mvc/spring-mvc.xsd">
        <import resource="dao.xml"/>
		<!--  注册service层-->
	<bean id="hrmsDeptService" class="com.qf.service.HrmsDeptServiceImpl">
	     <property name="hrmsDeptDao" ref="hrmsDeptDao"></property>
	</bean>	
		<bean id="hrmsProjectService" class="com.qf.service.HrmsProjectServiceImpl">
	<property name="hrmsDeptDao" ref="hrmsDeptDao"></property>
	<property name="hrmsProjectDao" ref="hrmsProjectDao"></property>
	</bean>
	<bean id="hrmsStaffService" class="com.qf.service.HrmsStaffServiceImpl">
	<property name="hrmsDeptDao" ref="hrmsDeptDao"></property>
	<property name="hrmsProjectDao" ref="hrmsProjectDao"></property>
	<property name="hrmsStaffDto" ref="hrmsStaffDao"></property>
	</bean>
	
	<bean id="hrmsResumeService" class="com.qf.service.HrmsResumeServiceImpl">
	     <property name="hrmsResumeDao" ref="hrmsResumeDao"></property>
	</bean>	
	
	<bean id="hrmsChtypeService" class="com.qf.service.HrmsChtypeServiceImpl">
	     <property name="hrmsChtypeDao" ref="hrmsChtypeDao"></property>
	</bean>	
	
	<bean id="hrmsChannelService" class="com.qf.service.HrmsChannelServiceImpl">
	     <property name="hrmsChannelDao" ref="hrmsChannelDao"></property>
	     <property name="hrmsChtypeDao" ref="hrmsChtypeDao"></property>
	</bean>	
	
	
	<bean id="hrmsDemandService" class="com.qf.service.HrmsDemandServiceImpl">
	     <property name="hrmsDeptDao" ref="hrmsDeptDao"></property>
	     <property name="hrmsProjectDao" ref="hrmsProjectDao"></property>
	     <property name="hrmsDemandDao" ref="hrmsDemandDao"></property>
	</bean>	
	
	
	<bean id="hrmsPrecontractService" class="com.qf.service.HrmsPrecontractServiceImpl">
	     <property name="hrmsPrecontractDao" ref="hrmsPrecontractDao"></property>
    <property name="hrmsResumeDao" ref="hrmsResumeDao"></property>
	</bean>	
	
	
	
	<bean id="hrmsInterviewService" class="com.qf.service.HrmsInterviewServiceImpl">
	     <property name="hrmsInterviewDao" ref="hrmsInterviewDao"></property>
    <property name="hrmsResumeDao" ref="hrmsResumeDao"></property>
	</bean>	
	
	
</beans>
(五)在action层的注解

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.qf.dto.HrmsChannelDto;
import com.qf.dto.HrmsChtypeDto;
import com.qf.dto.PageDto;
import com.qf.service.HrmsChannelService;
import com.qf.service.HrmsChtypeService;

@Controller
public class HrmsChannelAction {
	@Autowired
	@Qualifier("hrmsChtypeService")
	private HrmsChtypeService hrmsChtypeService;
	@Autowired
	@Qualifier("hrmsChannelService")
	private HrmsChannelService hrmsChannelService;

	public void setHrmsChtypeService(HrmsChtypeService hrmsChtypeService) {
		this.hrmsChtypeService = hrmsChtypeService;
	}

	public void setHrmsChannelService(HrmsChannelService hrmsChannelService) {
		this.hrmsChannelService = hrmsChannelService;
	}

	@RequestMapping("/preAddChannel.do")
	public ModelAndView preAddChannel(HttpServletRequest request, HttpServletResponse response) {
		ModelAndView mv = new ModelAndView();
		List<HrmsChtypeDto> findAllChtype = hrmsChtypeService.findAllChtype();
		mv.addObject("list", findAllChtype);
		mv.setViewName("/channel/addchannel.jsp");
		return mv;
	}
}





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值