SSM图书管理(二)

本篇文章主要讲述SSM框架搭建需要进行的相关配置。
(1)web.xml配置


<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  xmlns="http://java.sun.com/xml/ns/javaee"  
  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"  
  version="3.0"> 
  
  
  <filter>
     <filter-name>CharacterEncodingfilter-name>
     <filter-class>org.springframework.web.filter.CharacterEncodingFilterfilter-class>
     <init-param>
        <param-name>encodingparam-name>
        <param-value>UTF-8param-value>
     init-param>
  filter>
  <filter-mapping>
     <filter-name>CharacterEncodingfilter-name>
     <url-pattern>/*url-pattern>
  filter-mapping>
  
  
  <context-param>
  	<param-name>contextConfigLocationparam-name>
  	<param-value>classpath:applicationContext.xmlparam-value>
  context-param>
  
  <listener>          
   <listener-class>org.springframework.web.context.ContextLoaderListenerlistener-class>  
  listener>  
  
  
  <servlet>
  	<servlet-name>mvc-dispatcherservlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServletservlet-class>
  	
  	<init-param>
  		<param-name>contextConfigLocationparam-name>
  		<param-value>classpath:springMVC.xmlparam-value>
  	init-param>
  	<load-on-startup>1load-on-startup>
  servlet>
  
  <servlet-mapping>
  	<servlet-name>mvc-dispatcherservlet-name>
  	<url-pattern>/url-pattern>
  servlet-mapping>
web-app>

(2)applicationContext.xml配置


<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:jdbc="http://www.springframework.org/schema/jdbc"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:mvc="http://www.springframework.org/schema/mvc"
	xsi:schemaLocation="
     http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
     http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
     http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
     http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
     http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
     http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd">
	
     
     <context:annotation-config/>
     <context:component-scan base-package="service">context:component-scan>
	 
	 <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">  
	  <property name="driverClassName">  
	      
	      <value>com.mysql.jdbc.Drivervalue>  
	  property>  
	  <property name="url">  
	      <value>jdbc:mysql://localhost:3306/15ssm?characterEncoding=UTF-8value>  
	  property>  
	  <property name="username">  
	      <value>rootvalue>  
	  property>  
	  <property name="password">  
	      <value>chengvalue>  
	  property>  	
	bean>

	
	
	<bean id="sqlSession" class="org.mybatis.spring.SqlSessionFactoryBean">
		<property name="typeAliasesPackage" value="pojo" />
		<property name="dataSource" ref="dataSource"/>
		<property name="mapperLocations" value="classpath:mapper/*.xml"/>
	bean>
	
	
	<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
		<property name="basePackage" value="mapper">property>	
	bean>
beans>


(3)springMVC.xml配置


<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:jdbc="http://www.springframework.org/schema/jdbc"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd 
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd">

	
    <context:annotation-config/>

    <context:component-scan base-package="control">
          <context:include-filter type="annotation" 
          expression="org.springframework.stereotype.Controller"/>
    context:component-scan>
	
	
    <mvc:annotation-driven />
    
    <mvc:default-servlet-handler />

	
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
        <property name="prefix" value="/curp/" />
        <property name="suffix" value=".jsp" />
    bean>
beans>

你可能感兴趣的:(SSM)