- Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”.
SSM programming, namely SpringMVC + Spring + MyBatis integration, is the most popular JavaEE development technology architecture at present. In fact, the essence of Ssm integration is just to integrate MyBatis into Spring.
Because SpringMVC is originally part of Spring, it doesn’t have to be integrated.
SSM integration can be implemented in two ways: XML – based configuration and annotation – based.
Set up the SSM development environment
maven pom.xml
Plug-in:
Configure web. XML
(1) Register ContextLoaderListener
Register the ServletContext listener implementation class, ContextLoaderListener, to create the Spring container and place the created Spring container objects into the scope of the ServletContext.
(2) Register character set filters
Registered character set filter, used to solve the problem of garbled characters when the request parameters contain Chinese characters.
(3) Configure the central scheduler
When configuring the central scheduler, note that the SpringMVC configuration file name is not the same as the other Spring configuration file names. The purpose of this is for the Spring container to create beans that manage the Spring configuration file, and the SpringMVC container is responsible for initiating the view-layer beans.
SSM integrated annotation development
Project: SSM
Requirements: Complete student registration and information browsing.
Build table Student
Use the Student table
Creating a Web Project
Project name SSM
Maven rely on
Plug-in:
Define packages and organize the program structure.
The JSP file:
Writing configuration files
Jdbc property configuration file jdbc.properties
The Spring configuration file applicationContext.xml
Springmvc configuration file:
springmvc.xml
mybatis.xml
Define the web. The XML
1) Register ContextLoaderListener
2) Register DisatcherServlet
3) Register character set filters
4) Create both the Spring configuration file and the SpringMVC configuration file
The entity class Student
Dao interface and SQL mapping files
Service interface and implementation classes
The Service interface
The Service implementation class
Processor definition
StuentController.java
Define view – home page file – index.jsp
Specify path:
Specify the base tag
Register student page – addstudent.jsp
Browse the student page – liststudent.jsp
The page table
Js:
The introduction of the JQuery
Js ajax launched
Registration success page — success.jsp
Registration failure page – fail.jsp