Use of idea 5 -- create project 2

Keywords: Spring Maven Mybatis xml

1. Create WEB project

The community version does not have the function of creating a web project, so it can only create a maven web project. Here, the enterprise version of cracking is used.

1.1 creation steps

File-New-Project

In the pop-up window, select Java Enterprise - project SDK - Java EE version - Application Server

Project SDK: jdk version

Java EE Version: set the version of Java EE

Application Server: setting up the server

Then select We application, as shown in the figure:

Note: it is OK to uncheck

Select Next, and enter the project name and workspace, as shown in the figure:

Click Finish to finish the creation.

1.2 demo of Servlet

1.2.1 index.jsp

<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2020/1/15
  Time: 21:04
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
  <head>
    <title>zoudmBean</title>
  </head>
  <body>
  <form action="addUser" method="post">
    User name:<input type="text" name="username" /><br>
    Age:<input type="text" name="age" /><br>
    <input type="submit" value="Submission" />
  </form>
  </body>
</html>

1.2.2 servlet writing

1. To create a Servlet

Right click the src directory, New -- create new Servlet

Enter Servlet information in the pop-up window

Click OK to complete the creation

2. Write Servlet

We found that @ WebServlet(name = "AddUser") was automatically annotated on the class after the Servlet was created. Here we use version 4.0. The Servlet supports annotation development, so we use annotation development here

1. Add access path

Add urlPatterns attribute to @ WebServlet(name = "AddUser")

@WebServlet(name = "AddUser",urlPatterns = "/addUser")

2. servlet code

package com.bjc.web;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "AddUser",urlPatterns = "/addUser")
public class AddUser extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // Set encoding
        request.setCharacterEncoding("utf-8");
        String username = request.getParameter("username");
        String userage = request.getParameter("age");
        System.out.println("username = " + name + "   age = " + userage);
    }
}

3. Run web project

Because we have configured tomcat before, there will be a tomcat icon in the toolbar. We can click run directly, as shown in the figure:

Start successfully, run project automatically

Enter the corresponding information on the page and click Submit, as shown in the figure below:

java background execution result

1.2.3 user defined access path

As shown in the picture:

In the pop-up window, select tomcat Server - modify URL, as shown in the figure:

Select Deployment again and modify the Application Context, as shown in the figure:

Note: the access path and URL of Application Context in Deployment are modified synchronously, that is, the Application Context is modified, and then the URL will be changed automatically.

2. Create Maven's aggregation project

2.1 project structure

manager

         |----------manager pojo(jar)

         |----------manager dao(jar)

         |----------manager service(jar)

         |----------manager web(war)

2.2 create parent project

1. Click create project, as shown:

2. Select Maven, check create from... And select site, as shown:

3. Click next to enter the corresponding information

4. Click next, fill in the corresponding information, and finish, as shown in the figure:

5. Delete some information automatically generated by pom.xml file. You can also delete it without deleting it

<?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.bjc</groupId>
  <artifactId>manager</artifactId>
  <version>1.0-SNAPSHOT</version>

  <name>Maven</name>

</project>

2.3 create subproject

1. Select the parent project manager and click File - New - Module

2. In the pop-up window, select Maven, Create from... And Quickstart, as shown:

Note: since the pojo project I created here is packaged in jar, quickstart is used

3. Click next and fill in the project name, as shown in the figure:

4. Click next and follow the prompts.

Create the sub projects of dao, service and web, as shown in the figure:

2.3 add dependency management to parent project

<?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.bjc</groupId>
  <artifactId>manager</artifactId>
  <packaging>pom</packaging>
  <version>1.0-SNAPSHOT</version>
  <modules>
    <module>manage-pojo</module>
    <module>manage-dao</module>
    <module>manage-service</module>
    <module>manage-web</module>
  </modules>

  <!--It can be deleted. The value can be customized. The meaning is idea Right side Maven For display, the default is the project name-->
  <name>manage</name>

  <!--Definition jar Edition-->
  <properties>
    <junit.version>4.12</junit.version>
    <spring.version>4.1.3.RELEASE</spring.version>
    <mybatis.version>3.2.8</mybatis.version>
    <mybatis.spring.version>1.2.2</mybatis.spring.version>
    <mysql.version>5.1.32</mysql.version>
    <druid.version>1.0.9</druid.version>
    <jstl.version>1.2</jstl.version>
    <servlet.version>2.5</servlet.version>
    <tomcat.version>2.2</tomcat.version>
    <jsp.version>2.0</jsp.version>
  </properties>

  <!-- Dependency management -->
  <dependencyManagement>
    <dependencies>
      <!--Junit-->
      <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>${junit.version}</version>
      </dependency>
      <!--mybatis-->
      <dependency>
        <groupId>org.mybatis</groupId>
        <artifactId>mybatis</artifactId>
        <version>${mybatis.version}</version>
      </dependency>
      <!--mybatis And spring integration-->
      <dependency>
        <groupId>org.mybatis</groupId>
        <artifactId>mybatis-spring</artifactId>
        <version>${mybatis.spring.version}</version>
      </dependency>
      <!--Database related-->
      <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>${mysql.version}</version>
      </dependency>
      <dependency>
        <groupId>com.alibaba</groupId>
        <artifactId>druid</artifactId>
        <version>${druid.version}</version>
      </dependency>
      <!--spring-->
      <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>${spring.version}</version>
      </dependency>
      <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-beans</artifactId>
        <version>${spring.version}</version>
      </dependency>
      <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-jdbc</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-aspects</artifactId>
        <version>${spring.version}</version>
      </dependency>
      <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-test</artifactId>
        <version>${spring.version}</version>
      </dependency>
      <!--JSP And Servlet-->
      <dependency>
        <groupId>jstl</groupId>
        <artifactId>jstl</artifactId>
        <version>${jstl.version}</version>
      </dependency>
      <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>servlet-api</artifactId>
        <version>${servlet.version}</version>
      </dependency>
      <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jsp-api</artifactId>
        <version>${jsp.version}</version>
      </dependency>
    </dependencies>
  </dependencyManagement>
  <!--Configuration plug-ins-->
  <build>
    <!--Configure resource copy plug-ins-->
    <resources>
      <!--To configure main Next file-->
      <resource>
        <directory>src/main/java</directory>
        <includes>
          <!--take main Under and subdirectories.xml File copy-->
          <include>**/*.xml</include>
        </includes>
      </resource>
      <!--Configure files under resources -- >
      <resource>
        <directory>src/main/resources</directory>
        <includes>
          <include>**/*.xml</include>
          <include>**/*.properties</include>
        </includes>
      </resource>
    </resources>

    <!--To configure tomcat Plug in (declaration only in parent project)-->
    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>org.apache.tomcat.maven</groupId>
          <artifactId>tomcat7-maven-plugin</artifactId>
          <version>${tomcat.version}</version>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>
</project>

2.4 add dependency in subproject

2.4.1 add dependency for Dao project

<?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">
    <parent>
        <artifactId>manager</artifactId>
        <groupId>com.bjc</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>
    <artifactId>manage-dao</artifactId>
    <name>manage-dao</name>

    <dependencies>
        <!--dao Need dependence pojo-->
        <dependency>
            <groupId>com.bjc</groupId>
            <artifactId>manage-pojo</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
        <!--Add additional dependencies-->
        <!--mybatis-->
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis</artifactId>
        </dependency>
        <!--mybatis And spring integration-->
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis-spring</artifactId>
        </dependency>
        <!--Database related-->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid</artifactId>
        </dependency>
    </dependencies>

</project>

2.4.2 add dependency in service project

<?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">
    <parent>
        <artifactId>manager</artifactId>
        <groupId>com.bjc</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>manage-service</artifactId>

    <name>manage-service</name>

    <dependencies>
        <!--service Need dependence Dao engineering-->
        <dependency>
            <groupId>com.bjc</groupId>
            <artifactId>manage-dao</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aspects</artifactId>
        </dependency>
    </dependencies>

</project>

2.4.3 add the dependence of web project

<?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">
    <parent>
        <artifactId>manager</artifactId>
        <groupId>com.bjc</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>manage-web</artifactId>
    <packaging>war</packaging>

    <dependencies>
        <!-- web Engineering dependence service -->
        <dependency>
            <groupId>com.bjc</groupId>
            <artifactId>manage-service</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
        </dependency>
        <!--JSP And Servlet-->
        <dependency>
            <groupId>jstl</groupId>
            <artifactId>jstl</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jsp-api</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
        </dependency>
    </dependencies>

    <!--Add plug-ins-->
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.tomcat.maven</groupId>
                <artifactId>tomcat7-maven-plugin</artifactId>
                <configuration>
                    <path>/</path>
                    <port>9090</port>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

2.4 start test code

2.4.1 pojo definition

package com.bjc.pojo;
public class User {
    private Integer id;
    private String username;
    private String address;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }
}

2.4.2 Mapper

Interface:

package com.bjc.mapper;

import com.bjc.pojo.User;

import java.util.List;

public interface UserMapper {
    public List<User> getUsers();
}

Profile:

<?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="com.bjc.mapper.UserMapper">

    <select id="getUsers" resultType="com.bjc.pojo.User">
        select * from user
	</select>

</mapper>

2.4.3 create test class in web project

When we introduced dependency, Junit's dependency was introduced into the web layer, so our test classes were all in the web engineering.

1. Complete maven project directory

Create a new java and resources directory in main

Create a new test directory under src

2. Add profile

Create three new directories under the resource directory of the web project, as shown in the figure:

2.1 mybatis directory file

mybatisConfig.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration
  PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
  "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
    <settings> 
        <!-- Print query statement -->
        <setting name="logImpl" value="STDOUT_LOGGING" />
    </settings>
</configuration>

2.2 resource directory

db.properties

jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/mybatis?characterEncoding=utf-8
jdbc.username=root
jdbc.password=root

2.3 spring directory

applicationContext_action.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" xmlns:tx="http://www.springframework.org/schema/tx"
	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
		http://www.springframework.org/schema/tx 
		http://www.springframework.org/schema/tx/spring-tx.xsd
		http://www.springframework.org/schema/aop 
		http://www.springframework.org/schema/aop/spring-aop.xsd
		">  
	
	<context:component-scan base-package="com.bjc.web"></context:component-scan>
	
</beans>
	

applicationContext_biz.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" xmlns:tx="http://www.springframework.org/schema/tx"
	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
		http://www.springframework.org/schema/tx 
		http://www.springframework.org/schema/tx/spring-tx.xsd
		http://www.springframework.org/schema/aop 
		http://www.springframework.org/schema/aop/spring-aop.xsd
		">  

	<context:component-scan base-package="com.bjc.service"/>
	<!-- <bean id="depBiz" class="cn.bjc.biz.impl.DepBiz"></bean> -->
	
</beans>
	

applicationContext_tx.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" xmlns:tx="http://www.springframework.org/schema/tx"
	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
		http://www.springframework.org/schema/tx 
		http://www.springframework.org/schema/tx/spring-tx.xsd
		http://www.springframework.org/schema/aop 
		http://www.springframework.org/schema/aop/spring-aop.xsd
		">  

	<!-- dataSource Defined in dao.xml Medium, so we can't find it here, so we need to introduce -->
	<import resource="classpath:spring/applicationContext_dao.xml"></import>
	<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
		<property name="dataSource" ref="dataSource" />
	</bean>
	
	<tx:advice id="advice" transaction-manager="transactionManager">
	    <tx:attributes>	     
	      <tx:method name="do*" propagation="REQUIRED"/>
	      <tx:method name="add*" propagation="REQUIRED"/>
	      <tx:method name="update*" propagation="REQUIRED"/>
	      <tx:method name="save*" propagation="REQUIRED"/>
	      <tx:method name="delete*" propagation="REQUIRED"/>
	      <tx:method name="*" read-only="true"/>
	    </tx:attributes>
	</tx:advice>
	
	<aop:config>
		<aop:pointcut id="serviceMethod" expression="execution(* com.bjc.service.impl.*.*(..))"/>
		<aop:advisor pointcut-ref="serviceMethod" advice-ref="advice" />
	</aop:config>
	
</beans>
	

applicationContext_dao.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" xmlns:tx="http://www.springframework.org/schema/tx"
	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
		http://www.springframework.org/schema/tx 
		http://www.springframework.org/schema/tx/spring-tx.xsd
		http://www.springframework.org/schema/aop 
		http://www.springframework.org/schema/aop/spring-aop.xsd
		">
	<!-- Configuration analysis properties Tool class of file -->
	<context:property-placeholder location="classpath:resource/*.properties"></context:property-placeholder>

	<!-- Automatic scanning -->  
    <context:component-scan base-package="com.bjc.mapper"/>

    <!-- Define data source Bean -->
   <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
		<property name="url" value="${jdbc.url}"/>
		<property name="username" value="${jdbc.username}"/>
		<property name="password" value="${jdbc.password}"/>
		<property name="driverClassName" value="${jdbc.driver}"/>
	    <property name="maxActive" value="10"/>
	    <property name="minIdle" value="3"/>
	</bean>
	
	<!-- Load mybatis Core profile -->
	<bean class="org.mybatis.spring.SqlSessionFactoryBean" id="sqlSessionFactory">
		<!-- data source -->
		<property name="dataSource" ref="dataSource"></property>
		<!-- Core profile -->
		<property name="configLocation" value="classpath:mybatis/mybatisConfig.xml"></property>
		<!-- Configure alias package scanning  name by typeAliasesPackage  value by pojo Package name-->
		<property name="typeAliasesPackage" value="com.bjc.pojo"></property>
	</bean>
    
    <!-- DAO The package name of the interface, Spring Will automatically find the class under it -->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
 		<property name="basePackage" value="com.bjc.mapper" />
 	</bean>
</beans>

springMvc.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:mvc="http://www.springframework.org/schema/mvc"
    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
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd">

    <!-- Start Autoscan -->
    <context:component-scan base-package="com.bjc.web" />

    <!-- register MVC Annotation driven -->
    <mvc:annotation-driven />

    <!-- How static resources can be accessed -->
    <mvc:default-servlet-handler />

    <!-- To configure the view parser, you can set it explicitly or not. If not, the SpringMVC Default settings for -->
    <bean id="viewResolver"
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/" />
        <property name="suffix" value=".jsp" />
    </bean>

    <!-- Configure static resource mapping -->
    <mvc:resources mapping="/css/**" location="/css/"></mvc:resources>
    <mvc:resources mapping="/js/**" location="/js/"></mvc:resources>

    <!-- If you do not use file upload, you do not need to configure it. Of course, if you do not use file upload, you do not need to introduce upload component package into the configuration file -->
    <bean id="multipartResolver"    
        class="org.springframework.web.multipart.commons.CommonsMultipartResolver">    
        <!-- Default encoding -->  
        <property name="defaultEncoding" value="utf-8" />    
        <!-- Maximum file size -->  
        <property name="maxUploadSize" value="10485760000" />    
        <!-- Maximum in memory -->  
        <property name="maxInMemorySize" value="40960" />    
    </bean>   
    
</beans>

3. Write test class

package com.bjc.test;

import com.bjc.mapper.UserMapper1;
import com.bjc.pojo.User;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.util.List;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:spring/applicationContext_dao.xml")
public class ManageTest {
    @Autowired
    private UserMapper1 userMapper1;

    @Test
    public void test(){
        List<User> list = userMapper1.getUsers();
        System.out.println(list.toString());
    }
}

The operation result is correct, and the integration is completed here.

133 original articles published, 7 praised, 4126 visited
Private letter follow

Posted by le007 on Sat, 18 Jan 2020 08:10:39 -0800