Create projects and integrate ideas into the SSM framework
Create a project
Since springMVC will be configured later, create a Maven project using the Web skeleton of IDEA.
image
Create the project directory as follows, and the packages and files required for the project have been manually created:
image
In the figure above, application. XML is the Spring configuration file, log4j is the logging configuration file, and SpringMVC.xml is the springMVC configuration file
Configure the required dependencies in the POM.xml file, as shown below for the entire project.
<pre style=”box-sizing: border-box; outline: none; margin: 0px; padding: 0px; border: 0px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-numeric: inherit; font-variant-east-asian: inherit; font-weight: 400; font-stretch: inherit; font-size: 18px; line-height: inherit; font-family: couriernew, courier, monospace; vertical-align: baseline; color: rgb(93, 93, 93); letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-style: initial; text-decoration-color: initial;” >
<? The XML version = "1.0" encoding = "utf-8"? > < project XMLNS = "http://maven.apache.org/POM/4.0.0" XMLNS: xsi = "http://www.w3.org/2001/XMLSchema-instance" Xsi: schemaLocation = "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" > < modelVersion > 4.0.0 < / modelVersion > < groupId > com, hust. Demo - SSM < / groupId > < artifactId > demo < / artifactId > <version> 1.0-snapshot </version> <packaging>war</packaging> <name> Demo Maven Webapp</name> <! -- FIXME change it to the project's website --> <url>http://www.example.com</url> <properties> < project. Build. SourceEncoding > utf-8 < / project. Build. SourceEncoding > < maven.com piler. Source > 1.8 < / maven.com piler source > < maven.com piler target > 1.8 < / maven.com piler. Target > < spring. The version > 5.0.2. RELEASE < / spring. Version > < slf4j version > 1.6.6 < / slf4j version > < log4j. Version > 1.2.12 < / log4j version > < mysql. Version > 5.1.6 < / mysql version > <mybatis. Version >3.4.5</mybatis. Version > </properties> <dependency> <groupId>org.aspectj</groupId> < artifactId > aspectjweaver < / artifactId > < version > 1.6.8 < / version > < / dependency > < the dependency > <groupId>org.springframework</groupId> <artifactId>spring-aop</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-test</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-tx</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jdbc</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId> <version>4.12</version> <scope>compile</scope> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>${mysql.version}</version> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId> servlet-API </artifactId> <version>2.5</version> <scope> Provided </scope> </dependency> <dependency> < < the groupId > javax.mail. Servlet. JSP/groupId > < artifactId > JSP - API < / artifactId > < version > 2.0 < / version > < scope > provided < / scope > </dependency> <groupId> JSTL </groupId> <artifactId> JSTL </artifactId> <version>1.2</version> </dependency> <! -- log start --> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>${log4j.version}</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>${slf4j.version}</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> <version>${slf4j.version}</version> </dependency> <! -- log end --> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> <version>${mybatis.version}</version> </dependency> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis-spring</artifactId> <version>1.3.0</version> </dependency> <groupId> c3P0 </groupId> <artifactId> </artifactId> <version>0.9.1.2</version> <type>jar</type> <scope>compile</scope> </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> < version > 2.9.0 < / version > < / dependency > < the dependency > < groupId > com. Fasterxml. Jackson. Core < / groupId > < artifactId > Jackson - core < / artifactId > < version > 2.9.0 < / version > < / dependency > < the dependency > < the groupId > com. Fasterxml. Jackson. Core < / groupId > < artifactId > Jackson - annotations < / artifactId > < version > 2.9.0 < / version > </dependency> </dependencies> <build> <finalName>demo</finalName> <pluginManagement><! -- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) --> <plugins> <plugin> < artifactId > maven - clean - plugin < / artifactId > < version > 3.1.0 < / version > < / plugin > <! -- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging --> Maven-resources-plugin </artifactId> <version>3.0.2</version> </plugin> <plugin> < artifactId > maven -- the compiler plugin < / artifactId > < version > 3.8.0 < / version > < / plugin > < plugin > < artifactId > maven - surefire plugin < / artifactId > < version > 2.22.1 < / version > < / plugin > < plugin > < artifactId > maven - war - the plugin < / artifactId > < version > 3.2.2 < / version > < / plugin > < plugin > < artifactId > maven -- install plugin < / artifactId > < version > 2.5.2 < / version > < / plugin > < plugin > Maven-deploy-plugin </artifactId> <version>2.8.2</version> </plugin> </plugins> </pluginManagement> </build> </project>Copy the code
</pre>
So at this point, the skeleton of the project is built, the project’s dependencies have been imported, and then introduce the integration idea.
Second, SSM integration ideas
For purposes of integration, the Service layer needs to be able to invoke dao layer methods through dependency injection and the Controller layer needs to invoke Service layer methods through dependency injection. So, the basic idea of integration is to use Spring to integrate MyBatis with springMVC.
image
Mybatis configuration
First, let’s configure the MyBatis framework.
Create database demo_SSM and create account table
The SQL statement is as follows:
<pre style=”box-sizing: border-box; outline: none; margin: 0px; padding: 0px; border: 0px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-numeric: inherit; font-variant-east-asian: inherit; font-weight: 400; font-stretch: inherit; font-size: 18px; line-height: inherit; font-family: couriernew, courier, monospace; vertical-align: baseline; color: rgb(93, 93, 93); letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-style: initial; text-decoration-color: initial;” >
CREATE DATABASE `demo_ssm`; USE `demo_ssm`; DROP TABLE IF EXISTS `account`; CREATE TABLE `account`( `id` INT(11) NOT NULL AUTO_INCREMENT, `name` VARCHAR(32), `money` DOUBLE, PRIMARY KEY(`id`) )ENGINE=INNODB DEFAULT CHARSET=utf8; INSERT INTO ` account ` (` name `, ` money `) VALUES (' zhao, 99999.99), (11111.1), 'zhang mowgli, (' wood wan qing, 22222.22);Copy the code
</pre>
Create an account entity class
<pre style=”box-sizing: border-box; outline: none; margin: 0px; padding: 0px; border: 0px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-numeric: inherit; font-variant-east-asian: inherit; font-weight: 400; font-stretch: inherit; font-size: 18px; line-height: inherit; font-family: couriernew, courier, monospace; vertical-align: baseline; color: rgb(93, 93, 93); letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-style: initial; text-decoration-color: initial;” >
public class Account implements Serializable {
private Integer id;
private String name;
private Double money;
//getter and setter
//toString
}
Copy the code
</pre>
3. Develop the persistence layer interface with annotations
<pre style=”box-sizing: border-box; outline: none; margin: 0px; padding: 0px; border: 0px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-numeric: inherit; font-variant-east-asian: inherit; font-weight: 400; font-stretch: inherit; font-size: 18px; line-height: inherit; font-family: couriernew, courier, monospace; vertical-align: baseline; color: rgb(93, 93, 93); letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-style: initial; text-decoration-color: initial;” >
package com.hust.dao;
public interface IAccountDao {
@Select("select * from account")
public List<Account> findAllAccount();
}
Copy the code
</pre>
At this point Mybatis has been configured, the data source has not been configured yet, we will wait until the integration of Spring to configure and test.
Spring configures and integrates Mybatis
Spring configuration
The applicationContext. XML file now configures:
<pre style=”box-sizing: border-box; outline: none; margin: 0px; padding: 0px; border: 0px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-numeric: inherit; font-variant-east-asian: inherit; font-weight: 400; font-stretch: inherit; font-size: 18px; line-height: inherit; font-family: couriernew, courier, monospace; vertical-align: baseline; color: rgb(93, 93, 93); letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-style: initial; text-decoration-color: initial;” >
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<!-- 配置扫描-->
<context:component-scan base-package="com.hust">
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>
</beans>
Copy the code
</pre>
Note:
Autowiring requires scanning for annotations in the package, so configure to enable annotation scanning. There are two ways to enable annotation scanning: <context:annotation-config/> and <context: Component-scan >. The similarities and differences are as follows:
<context:annotation-config>: Annotation scanning is for beans that have already been registered in the Spring container
<context:component-scan>: not only has all the functionality of <context:annotation-config>, but also can scan the corresponding bean under the specified package
Spring integration with Mybatis
Analysis of ideas:
Mybatis framework can automatically generate a proxy object, so the persistence layer, we only write an interface and annotations, the specific implementation class is by the framework to help us to complete, the database CRUD is also achieved through this proxy object. So, as long as we can store the generated proxy object in the container and let the Spring framework control it, the integration is successful.
Another key point is that Mybatis framework uses SqlSessionFactory factory instance to create SqlSession instance, from which we can operate on the database.
In short, the key to Spring’s Mybatis integration is to enable the container to control the SqlSessionFactoryBean class.
Specific configuration
The specific configuration is divided into three parts:
1. Configure connection **** pool ****. 2. Configure a scanner that scans packets
Therefore, the configuration is as follows:
<pre style=”box-sizing: border-box; outline: none; margin: 0px; padding: 0px; border: 0px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-numeric: inherit; font-variant-east-asian: inherit; font-weight: 400; font-stretch: inherit; font-size: 18px; line-height: inherit; font-family: couriernew, courier, monospace; vertical-align: baseline; color: rgb(93, 93, 93); letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-style: initial; text-decoration-color: initial;” >
<? The XML version = "1.0" encoding = "utf-8"? > <beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <! <context:component-scan base-package="com.hust"> </context:component-scan> <! - configuration data source - > < bean id = "dataSource" class = "boPooledDataSource com.mchange.v2.c3p0.Com" > < property name = "driverClass" value="com.mysql.jdbc.Driver"/> <property name="jdbcUrl" value="jdbc:mysql:///demo_ssm"/> <property name="user" value="root"/> <property name="password" value="root"/> </bean> <! - allocation of SqlSession factory - > < bean id = "sqlSessionFactory" class = "org. Mybatis. Spring. SqlSessionFactoryBean" > < property name="dataSource" ref="dataSource"/> </bean> <! Configuration, scan the package -- -- > < bean id = "mapperScanner" class = "org. Mybatis. Spring. Mapper. MapperScannerConfigurer" > < property name="basePackage" value="com.hust.dao"/> </bean> </beans>Copy the code
</pre>
With this configuration, the Spring container can create the sqlSession factory class. Add the @Repository annotation to the IAccountDao, and the proxy object for the AccountDao interface can be container-managed and consolidated. Let’s test with a test class:
<pre style=”box-sizing: border-box; outline: none; margin: 0px; padding: 0px; border: 0px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-numeric: inherit; font-variant-east-asian: inherit; font-weight: 400; font-stretch: inherit; font-size: 18px; line-height: inherit; font-family: couriernew, courier, monospace; vertical-align: baseline; color: rgb(93, 93, 93); letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-style: initial; text-decoration-color: initial;” >
@RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = {"classpath:applicationContext.xml"}) public class SpringTest { @Autowired private IAccountDao accountDao; @Test public void testSpring(){ List<Account> accounts = accountDao.findAllAccount(); for (Account account:accounts ) { System.out.println(account); }}}Copy the code
</pre>
The results are as follows:
<pre style=”box-sizing: border-box; outline: none; margin: 0px; padding: 0px; border: 0px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-numeric: inherit; font-variant-east-asian: inherit; font-weight: 400; font-stretch: inherit; font-size: 18px; line-height: inherit; font-family: couriernew, courier, monospace; vertical-align: baseline; color: rgb(93, 93, 93); letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-style: initial; text-decoration-color: initial;” >
Account{id=1, name=' zhao Min ', money=99999.99} Account{id=2, name=' zhang Wuji ', money=11111.1} Account{id=3, name=' mo Wanqing ', Money = 22222.22}Copy the code
</pre>
All accounts have been successfully queried, indicating that dependency injection can be implemented through the container. This indicates that Spring and MyBatis have been configured and integrated successfully.
PS: Here Spring uses @runwith and @contextConfiguration to integrate junit
For springMVC configuration
1. Configuration web. XML
The SpringMVC framework is designed around the DispatcherServlet, which handles all HTTP requests and responses. So we need to configure the web.xml file to map the requests we want the DispatcherServlet to handle.
<pre style=”box-sizing: border-box; outline: none; margin: 0px; padding: 0px; border: 0px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-numeric: inherit; font-variant-east-asian: inherit; font-weight: 400; font-stretch: inherit; font-size: 18px; line-height: inherit; font-family: couriernew, courier, monospace; vertical-align: baseline; color: rgb(93, 93, 93); letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-style: initial; text-decoration-color: initial;” >
<servlet>
<servlet-name>demo</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:springMVC.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>demo</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
Copy the code
</pre>
Obviously, you need to configure the servlet, along with the servlet mapping.
The <init-param> configuration lets us load the servlet configuration file at initialization.
2. Configuration for springMVC. XML
<pre style=”box-sizing: border-box; outline: none; margin: 0px; padding: 0px; border: 0px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-numeric: inherit; font-variant-east-asian: inherit; font-weight: 400; font-stretch: inherit; font-size: 18px; line-height: inherit; font-family: couriernew, courier, monospace; vertical-align: baseline; color: rgb(93, 93, 93); letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-style: initial; text-decoration-color: initial;” >
<? The XML version = "1.0" encoding = "utf-8"? > <beans xmlns="http://www.springframework.org/schema/beans" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <! <context:component-scan base-package="com.hust"> <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/> </context:component-scan> <bean id="internalResourceViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/pages/"/> <property name="suffix" value=".jsp"/> </bean> <! < MVC :annotation-driven/> </beans>Copy the code
</pre>
3. Write the AccountController class
<pre style=”box-sizing: border-box; outline: none; margin: 0px; padding: 0px; border: 0px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-numeric: inherit; font-variant-east-asian: inherit; font-weight: 400; font-stretch: inherit; font-size: 18px; line-height: inherit; font-family: couriernew, courier, monospace; vertical-align: baseline; color: rgb(93, 93, 93); letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-style: initial; text-decoration-color: initial;” >
@Controller @RequestMapping("/account") public class AccountController { @Autowired private IAccountService accountService; @RequestMapping("/all") public String findAllAccounts(){ return "success"; }}Copy the code
</pre>
At this point, springMVC is configured, we start the server, and when we jump to the success.jsp page after accessing the/Account /all path, the following image appears.
image
The springMVC configuration is successful
Spring integration for springMVC
Thought analysis
When the server is started, the applicationContext.xml file is not loaded, and the Spring framework does not work, so you cannot use the @Autowire annotation to implement dependency injection and call service layer methods. So the idea is to load the configuration file and create the container when the server starts. In this way, the presentation layer can call the methods of the business layer.
The specific implementation
We set up listeners so that when the server starts, the configuration file is loaded and the container is initialized.
The final web.xml file looks like this:
<pre style=”box-sizing: border-box; outline: none; margin: 0px; padding: 0px; border: 0px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-numeric: inherit; font-variant-east-asian: inherit; font-weight: 400; font-stretch: inherit; font-size: 18px; line-height: inherit; font-family: couriernew, courier, monospace; vertical-align: baseline; color: rgb(93, 93, 93); letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-style: initial; text-decoration-color: initial;” >
<! DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc., / / DTD Web Application / 2.3 / EN "" http://java.sun.com/dtd/web-app_2_3.dtd" > < Web - app > < the display - the name > Archetype Created Web Application</display-name> <! Configure the spring-provided listener to load the container when the service is started. This listener loads a configuration file named ApplicationContext.xml in the Web-INF directory --> <listener> <listener-class> org.springframework.web.context.ContextLoaderListener </listener-class> </listener> <! <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext.xml</param-value> </context-param> <servlet> <servlet-name>demo</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:springMVC.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>demo</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> </web-app>Copy the code
</pre>
In the meantime, modify the AccountController class
<pre style=”box-sizing: border-box; outline: none; margin: 0px; padding: 0px; border: 0px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-numeric: inherit; font-variant-east-asian: inherit; font-weight: 400; font-stretch: inherit; font-size: 18px; line-height: inherit; font-family: couriernew, courier, monospace; vertical-align: baseline; color: rgb(93, 93, 93); letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-style: initial; text-decoration-color: initial;” >
@Controller @RequestMapping("/account") public class AccountController { @Autowired private IAccountService accountService; @RequestMapping("/all") public String findAllAccounts(){ List<Account> all = accountService.findAllAccount(); for (Account a:all ) { System.out.println(a); } return "success"; }}Copy the code
</pre>
When the success.jsp page is accessed, the back end outputs
<pre style=”box-sizing: border-box; outline: none; margin: 0px; padding: 0px; border: 0px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-numeric: inherit; font-variant-east-asian: inherit; font-weight: 400; font-stretch: inherit; font-size: 18px; line-height: inherit; font-family: couriernew, courier, monospace; vertical-align: baseline; color: rgb(93, 93, 93); letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-style: initial; text-decoration-color: initial;” >
Account{id=1, name=' zhao Min ', money=99999.99} Account{id=2, name=' zhang Wuji ', money=11111.1} Account{id=3, name=' mo Wanqing ', Money = 22222.22}Copy the code
</pre>
The accountService object can be injected through the container, and the integration is successful.
PS: Use the @RestController annotation to implement the API to separate the front end from the back end.
summary
The key is to use the Spring framework to integrate other frameworks, and understanding what the Spring framework does is crucial!
If you have any questions or write wrong place, welcome to leave a comment!