首页 > 代码库 > springmvc-mybatis

springmvc-mybatis

技术分享    

 

-----------------------------------------------------  以上是springmvc-mybatis的jar包-------------------------------------------------------------

 

 

<?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" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">  <display-name>springmvc-mybatis</display-name>  <welcome-file-list>    <welcome-file>index.html</welcome-file>    <welcome-file>index.htm</welcome-file>    <welcome-file>index.jsp</welcome-file>    <welcome-file>default.html</welcome-file>    <welcome-file>default.htm</welcome-file>    <welcome-file>default.jsp</welcome-file>  </welcome-file-list><!--    监听器,作用?    -->      <listener>        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>    </listener><!--   让webxml找到applicationContext.xml -->    <context-param>        <param-name>contextConfigLocation</param-name>        <param-value>        /WEB-INF/classes/applicationContext.xml        </param-value>    </context-param>              <servlet>        <servlet-name>springmvc-mybatis</servlet-name>        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>        <init-param>            <param-name>contextConfigLocation</param-name>            <param-value>              /WEB-INF/classes/springmvc-servlet.xml          </param-value>        </init-param>        <load-on-startup>1</load-on-startup>    </servlet>    <servlet-mapping>        <servlet-name>springmvc-mybatis</servlet-name>        <url-pattern>*.do</url-pattern>    </servlet-mapping></web-app>


 ----------------------------------------------------- 以上是web.xml的总配置-------------------------------------------------------------

 

<?xml version="1.0" encoding="UTF-8"?>     <!DOCTYPE configurationPUBLIC "-//mybatis.org//DTD Config 3.0//EN""http://mybatis.org/dtd/mybatis-3-config.dtd">   <configuration>    <!--     扫描所有实体类 -->    <typeAliases>        <package name="com.lovo.pojo"/>    </typeAliases></configuration>    

 ----------------------------------------------------- 以上是SqlMapConfig.xml的配置-------------------------------------------------------------

 

 

<?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:p="http://www.springframework.org/schema/p"    xmlns:mvc="http://www.springframework.org/schema/mvc"    xmlns:context="http://www.springframework.org/schema/context"    xsi:schemaLocation="http://www.springframework.org/schema/beans     http://www.springframework.org/schema/beans/spring-beans-4.2.xsd    http://www.springframework.org/schema/context    http://www.springframework.org/schema/context/spring-context-4.2.xsd    http://www.springframework.org/schema/mvc       http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd"> <!--    启动springmvc的注解    -->    <mvc:annotation-driven /><!--     注入所有的控制器-->    <context:component-scan base-package="com.lovo.controller" />                                  <!-- ViewResolver视图解析器 用于将返回的ModelAndView对象进行分离 -->    <bean class="org.springframework.web.servlet.view.UrlBasedViewResolver">        <property name="viewClass"            value="org.springframework.web.servlet.view.JstlView"></property>        <property name="prefix" value="http://www.mamicode.com/"></property>        <property name="suffix" value="http://www.mamicode.com/.jsp"></property>    </bean>                </beans>    

 ----------------------------------------------------- 以上是springmvc-servlet.xml的配置-------------------------------------------------------------

 

<?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:context="http://www.springframework.org/schema/context"    xmlns:aop="http://www.springframework.org/schema/aop"    xsi:schemaLocation="http://www.springframework.org/schema/beans    http://www.springframework.org/schema/beans/spring-beans-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/context    http://www.springframework.org/schema/context/spring-context-4.2.xsd">         <!--启用自动扫描 -->        <context:component-scan base-package="com.lovo" />        <!--      切面 -->        <aop:aspectj-autoproxy />         <!--        数据源连接数据库-->    <bean id="dataSource"        class="org.springframework.jdbc.datasource.DriverManagerDataSource">        <property name="driverClassName" value="http://www.mamicode.com/com.mysql.jdbc.Driver" />        <property name="url" value="http://www.mamicode.com/jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8" />        <property name="username" value="http://www.mamicode.com/root" />        <property name="password" value="http://www.mamicode.com/lovo" />    </bean>        <!-- 由spring来管理SqlSessionFactory    -->    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">        <property name="dataSource" ref="dataSource" />        <property name="configLocation" value="http://www.mamicode.com/classpath:SqlMapConfig.xml" />    </bean>                      <!-- mappers  扫描mapper下的所有mapper.xml -->    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">        <property name="basePackage" value="http://www.mamicode.com/com.lovo.mapper"></property>    </bean></beans>

 ----------------------------------------------------- 以上是applicationContext.xml的配置-------------------------------------------------------------

springmvc-mybatis