Using the SSM framework, it's definitely a Web project, so start with Web.xml web.xml .
To configure the spring project startup and start
Configure the Spring MVC front-end controller (load Springmvc.xml) to set the blocking rules
<?xml version= "1.0" encoding= "UTF-8"?> <web-app version= "3.0" xmlns= "Http://java.sun.com/xml/ns/javaee" Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" xsi:schemalocation= "Http://java.sun.com/xml/ns/javaee http ://java.sun.com/xml/ns/javaee/web-app_3_0.xsd > <!--Configure Spring to start with the project--> <context-param> <param -name>contextconfiglocation</param-name> <param-value>classpath:config/bean*.xml</param-value > </context-param> <listener> <listener-class> Org.springframework.web.context.contextloaderlistener</listener-class> </listener> <!--configuration Spring MVC front-end controller--> <servlet> <servlet-name>SpringMvc</servlet-name> <SERVLET-CLASS>ORG.SPR ingframework.web.servlet.dispatcherservlet</servlet-class> <!--Specify SPRINGMVC configuration file if not configured then default to find/web-inf/[ser Vlet name]-servlet.xml (that is, Classpath:[servlet name]-servlet.xml)--> <init-param> <Param-name>contextconfiglocation</param-name> <param-value>classpath:config/springmvc.xml</ Param-value> </init-param> </servlet> <!--map--> <servlet-mapping> <servlet-nam E>springmvc</servlet-name> <!--interception Rules: (Applicable to SPRINGMVC) 1. /* block all include JSP JS PNG CSS 2. *.action *.do intercepts the request at the end of Do action 3.
/intercept all (excluding JSP) (including JS png css)--> <url-pattern>*.action</url-pattern> </servlet-mapping>
</web-app>
Springmvc.xml
<?xml version= "1.0" encoding= "UTF-8"?> <beans "xmlns=" xmlns: Xsi= "Http://www.w3.org/2001/XMLSchema-instance" xmlns:p= "http://www.springframework.org/schema/p" 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-4.0.xsd Http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/ Spring-mvc-4.0.xsd Http://www.springframework.org/schema/context http://www.springframework.org/schema/context/ Spring-context-4.0.xsd "> <!--annotation scan--> <context:component-scan base-package=" com. Google.controller "/> <!--annotation driver: The default processor Mapper and processor adapter are deprecated (use this configuration to replace the processor mapper with the processor adapter's implementation class for a new)--> <mvc:annotat Ion-driven/> <!--configuration View parser--> <bean class= "Org.springframework.web.servlet.view. Internalresourceviewresolver "> <!--Configure the logical view prefix--> <property name=" prefix "value="/web-inf/jsp/"/&
Gt
<!--Configure the logical view suffix--> <property name= "suffix" value= ". jsp"/> </bean> </beans>
To this SPRING+SPRINGMVC consolidation complete
Here's spring+mybatis.
MyBatis General configuration file sqlmapconfig.xml
<?xml version= "1.0" encoding= "UTF-8"?> <!
DOCTYPE Mapper Public
"-//mybatis.org//dtd mapper 3.0//en"
"HTTP://MYBATIS.ORG/DTD/MYBATIS-3-MAPPER.DTD" >
<mapper namespace= "mapper. Usermapper ">
<select id=" Finduserbyid "parametertype=" Integer "resulttype=" user ">
select * from User where id = #{id}
</select>
</mapper>
Mapper.xml
<?xml version= "1.0" encoding= "UTF-8"?> <!
DOCTYPE Mapper Public
"-//mybatis.org//dtd mapper 3.0//en"
"HTTP://MYBATIS.ORG/DTD/MYBATIS-3-MAPPER.DTD" >
<mapper namespace= "mapper. Usermapper ">
<select id=" Finduserbyid "parametertype=" Integer "resulttype=" user ">
select * from User where id = #{id}
</select>
</mapper>
db.properties
Jdbc.driver=com.mysql.jdbc.driver
Jdbc.url=jdbc:mysql://localhost:3306/springmvc
jdbc.username=root
Jdbc.password=root
Bean.xml
<?xml version= "1.0" encoding= "UTF-8"?> <beans "xmlns=" xmlns: Xsi= "Http://www.w3.org/2001/XMLSchema-instance" xmlns:p= "http://www.springframework.org/schema/p" xmlns:context= "Http://www.springframework.org/schema/context" xmlns:aop= "HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP" xmlns:tx= " Http://www.springframework.org/schema/tx "xsi:schemalocation=" Http://www.springframework.org/schema/beans htt
P://www.springframework.org/schema/beans/spring-beans.xsd Http://www.springframework.org/schema/context
Http://www.springframework.org/schema/context/spring-context.xsd HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP Http://www.springframework.org/schema/aop/spring-aop.xsd Http://www.springframework.org/schema/tx htt P://www.springframework.org/schema/tx/spring-tx.xsd "> <context:property-placeholder location=" classpath: Config/db.properties "/> <!--willThe database connection pool is referred to spring management--> <bean name= "DataSource" class= "Com.mchange.v2.c3p0.ComboPooledDataSource" > <pro Perty name= "Jdbcurl" value= "${jdbc.url}" ></property> <property name= "Driverclass" value= "${jdbc.driver} "></property> <property name=" user "value=" ${jdbc.username} "></property> <property nam e= "Password" value= "${jdbc.password}" ></property> </bean> <!--mybatis factory--> <bean id= "s Qlsessionfactorybean "class=" Org.mybatis.spring.SqlSessionFactoryBean > <!--injection data source--> <property N Ame= "DataSource" ref= "DataSource" ></property> <!--mybatis Core configuration file location--> <property name= "conf
Iglocation "value=" Classpath:config/sqlmapconfig.xml "></property> </bean> <!--mapper Dynamic agent development enhanced scanning Without having to manually inject the factory, he would go to the spring container and find--> <bean class= "Org.mybatis.spring.mapper.MapperScannerConfigurer" > & lt;! --Automatically scan the mapper agent from the specified packageThe port is added to the container--> <property name= "basepackage" value= "com.
Google.mapper "></property> </bean> </beans>
Jar Bundle Dependencies
Pom.xml
<dependencies> <!--Spring MVC--> <!--Https://mvnrepository.com/artifact/org.springframewo Rk/spring-webmvc--> <dependency> <groupId>org.springframework</groupId> <artifactid>sp ring-webmvc</artifactid> <version>4.2.4.RELEASE</version> </dependency> <dependency&
Gt <groupId>jstl</groupId> <artifactId>jstl</artifactId> <VERSION>1.2&L T;/version> </dependency> <!--junit Test--> <dependency> <groupid>junit </groupId> <artifactId>junit</artifactId> <version>4.9</version> <scope >test</scope> </dependency> <!--mybatis--> <!--https://mvnrepository.com/artifact/org. Mybatis/mybatis--> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis< /artifacTid> <version>3.2.7</version> </dependency> <!--https://mvnrepository.com/artifact/ Org.mybatis/mybatis-spring--> <dependency> <groupId>org.mybatis</groupId> <artifactId> mybatis-spring</artifactid> <version>1.2.2</version> </dependency> <dependency> ;groupid>mysql</groupid> <artifactId>mysql-connector-java</artifactId> <version>
5.1.38</version> </dependency> <dependency> <groupId>com.mchange</groupId> <artifactId>c3p0</artifactId> <version>0.9.2.1</version> </dependency> <!-- Spring--> <!--https://mvnrepository.com/artifact/org.springframework/spring-aspects--> <dependency > <groupId>org.springframework</groupId> <artifactId>spring-aspects</artifactId> &L T;version>4.2.4.release</version> </dependency> <!--https://mvnrepository.com/artifact/org.springframework/spring-core--> <dependency> < Groupid>org.springframework</groupid> <artifactId>spring-core</artifactId> <version> 4.2.4.release</version> </dependency> <dependency> <groupId>org.slf4j</groupId> ;artifactid>slf4j-log4j12</artifactid> <version>1.7.25</version> </dependency> <!-- Https://mvnrepository.com/artifact/org.springframework/spring-jdbc--> <dependency> <groupId> Org.springframework</groupid> <artifactId>spring-jdbc</artifactId> <version>4.2.4. Release</version> </dependency> <!--https://mvnrepository.com/artifact/org.springframework/ Spring-orm--> <dependency> <groupId>org.springframework</groupId> <artifactid>spring-o Rm</artifactid> <version>4.2.4.release</version&Gt </dependency> <dependency> <groupId>org.springframework</groupId> <artifactid>sprin G-test</artifactid> <version>4.2.4.RELEASE</version> </dependency> <!--https:// Mvnrepository.com/artifact/org.springframework/spring-web--> <dependency> <groupId> Org.springframework</groupid> <artifactId>spring-web</artifactId> <version>4.2.4.release </version> </dependency> <dependency> <groupId>org.springframework</groupId> &L T;artifactid>spring-context</artifactid> <version>4.2.4.RELEASE</version> </dependency > <dependency> <groupId>org.springframework</groupId> <artifactid>spring-beans</art ifactid> <version>4.2.4.RELEASE</version> </dependency> <dependency> <groupid>or G.springframework</groupid> <ARTIFACTID>SPRing-expression</artifactid> <version>4.2.4.RELEASE</version> </dependency> </
Dependencies>
SSM Integration Complete