Spring + Springmvc + MyBatis Integration
Before Integration
Now we are new to the company. The company uses the SSM framework and Maven to build the project. We have learned SSH before, so we can get started relatively well and don't think it is too difficult, after entering the company for more than a week, I think the following are important:
In the company, the framework only requires you to understand, be familiar with the company's framework, and really need to use a java-based company, because the most important thing is the business. It is not too difficult to get started with the framework, but it is a little troublesome to get started with in-depth understanding. Many theoretical and theoretical questions are hard to understand. There must be a macro concept. In the future, we must gain an in-depth understanding of the mainstream frameworks I. Basic concepts.
Spirng
Springmvc
MyBatis
The basic concepts of the three frameworks will not be explained, because they are certainly understood at the beginning, and there is not much meaning in writing, but they must know what functions they are responsible.
Ii. SSM Integration
The idea of integration starts with the overall project structure, configuration file, and implementation class, because only one SSM environment is set up and only one business function is written. Forgive me.
Overall project structure
The Maven project adopts the agreed form:
Src/main/java storage java file src/main/resources storage configuration file src/test/java storage test class src/test/resources storage test class resource file pom. xml Maven configuration file
This small project uses spring4.2.3 + MyBatis3.2.6, which should be relatively new. If the Maven project is just started, I think pom. the configuration of xml files is troublesome. I don't know which dependent package to use, which leads to the failure of Maven project. This is also a headache for beginners. Although it is not difficult, I will give pom here. all configurations of xml.
4.0.0
Ssm4
Ssm4
0.0.1-SNAPSHOT
War
Ssm4
UTF-8
4.2.3.RELEASE
4.11
3.2.6
5.1.37
3.0-alpha-1
2.2
1.2
10.2.0.4.0
1.1.39
2.0
2.2
1.1.3
1.3.2
3.3.1
1.2.1
1.2.17
1.7.6
1.6.1
1.0.17
1.2.3
1.7.4
0.8.0.RELEASE
1.0.4
0.9.5.1
6.8.8
2.3.20
1.7
5.3.7
4.2
3.1
Maven-compiler-plugin
2.3.2
1.7
1.7
Maven-war-plugin
2.2
3.1
False
Junit
Junit
$ {Junit. version}
Test
Org. springframework
Spring-core
$ {Spring. version}
Org. springframework
Spring-beans
$ {Spring. version}
Org. springframework
Spring-context
$ {Spring. version}
Org. springframework
Spring-jdbc
$ {Spring. version}
Org. springframework
Spring-web
$ {Spring. version}
Org. springframework
Spring-webmvc
$ {Spring. version}
Org. springframework
Spring-aop
$ {Spring. version}
Org. springframework
Spring-tx
$ {Spring. version}
Org. springframework
Spring-orm
$ {Spring. version}
Org. springframework
Spring-context-support
$ {Spring. version}
Org. springframework
Spring-test
$ {Spring. version}
Org. springframework
Spring-jms
$ {Spring. version}
Org. mybatis
Mybatis
$ {Mybatis. version}
Org. mybatis
Mybatis-spring
1.2.2
Org. mybatis. caches
Mybatis-ehcache
1.0.2
Mysql
Mysql-connector-java
$ {Mysql. version}
Commons-logging
Commons-logging
$ {Commons-logging.version}
Log4j
Log4j
$ {Log4j. version}
Org. slf4j
Slf4j-log4j12
$ {Slf4j. version}
Org. slf4j
Slf4j-api
$ {Slf4j. version}
Javax. servlet. jsp
Jsp-api
$ {Jsp-api.version}
Javax. servlet
Servlet-api
$ {Servlet-api.version}
Javax. servlet
Jstl
$ {Jstl. version}
Org. springframework
Spring-test
$ {Spring. version}
Junit
Junit
$ {Junit. version}
Org. testng
Testng
$ {Testng. version}
Org. apache. commons
Commons-io
$ {Commons-io.version}
Org. apache. commons
Commons-lang3
$ {Commons-lang3.version}
Org. apache. commons
Commons-collections4
4.0
Org. kuali. commons
Commons-beanutils
1.8.3-kuali-4
Org. aspectj
Aspectjweaver
$ {Aspectjweaver. version}
Dom4j
Dom4j
$ {Dom4j. version}
Com. mchange
C3p0
${C3p0. version}
Integrate Spring and MyBatis
Configuration files integrated by spring and MyBatis
MyBatis ing File
select * from person
MyBatis configuration file
Because of the integration with spring, the configuration file of MyBatis basically does not need to write other information.
Here, spring and MyBatis are integrated.
Spring and springmvc Integration
Springmvc is included in spring and basically does not need to be configured separately.
Controller layer:
@Controllerpublic class PersonController { @Resource PersonService personService; @RequestMapping("person/listAll.action") public String listAll(Model model){ List personList = personService.listAll(); model.addAttribute("personList", personList); return "/person/jPersonList"; }}
Configuration of the web. xml file:
contextConfigLocation
classpath*:spring/spring-mybatis.xml
org.springframework.web.context.ContextLoaderListener
springmvc
org.springframework.web.servlet.DispatcherServlet
contextConfigLocation
classpath*:springmvc/springmvc-servlet.xml
springmvc
*.action
index.jsp
Running effect:
Summary
This is a very small project, but contains all the configurations required by SSM. In general, these configuration files are basically used for both large and small projects, the SSM environment can be built to gain a deeper understanding of its principles. Otherwise, we will only talk about the theory, no technical support, and no practical use.
The configuration files include:
Web. xml spring-mybatis.xml springmvc. xml mybatis. xml
After spring3, annotations gradually began to replace some of the functions of the configuration file. It also simplifies the configuration difficulty of the configuration file, and the learning time is not long. This tutorial is only suitable for beginners, please guide.
Project source code: Link: http://pan.baidu.com/s/1bnoMA4Z password: 43ob