zoukankan      html  css  js  c++  java
  • 整理一套Springboot整合Mybatis的模板

    1、创建springboot项目

    这里暂时先只勾选MySQL Driver和lombok,后面的mybatis依赖文件再在pom文件中添加。

    然后更改maven仓库的路径:

    这样,初始项目就搭建好了。

    2、添加必要的pom依赖

    引入mybatis和jdbc的依赖

    <!-- https://mvnrepository.com/artifact/org.mybatis.spring.boot/mybatis-spring-boot-starter -->
    <!--mybatis-->
    <dependency>
        <groupId>org.mybatis.spring.boot</groupId>
        <artifactId>mybatis-spring-boot-starter</artifactId>
        <version>2.1.3</version>
    </dependency>
    
    <!--jdbc一定要引入-->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-jdbc</artifactId>
    </dependency>
    

    同时,我这里把lombok的版本改成了最新版(其实按默认的来也是可以的)

    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <version>1.18.12</version>
    </dependency>
    

    同时,为了方便测试,还需要添加一个web依赖:

    <!--web依赖-->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    

    完整的pom文件:

    <?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>2.3.3.RELEASE</version>
            <relativePath/> <!-- lookup parent from repository -->
        </parent>
        <groupId>com.fan</groupId>
        <artifactId>springboot-mybatis</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <name>springboot-mybatis</name>
        <description>Demo project for Spring Boot</description>
    
        <properties>
            <java.version>11</java.version>
        </properties>
    
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter</artifactId>
            </dependency>
    
            <!-- https://mvnrepository.com/artifact/org.mybatis.spring.boot/mybatis-spring-boot-starter -->
            <!--mybatis-->
            <dependency>
                <groupId>org.mybatis.spring.boot</groupId>
                <artifactId>mybatis-spring-boot-starter</artifactId>
                <version>2.1.3</version>
            </dependency>
    
            <!--jdbc一定要引入-->
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-jdbc</artifactId>
            </dependency>
    
            <!--web依赖-->
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
            </dependency>
    
            <dependency>
                <groupId>mysql</groupId>
                <artifactId>mysql-connector-java</artifactId>
                <scope>runtime</scope>
            </dependency>
            <dependency>
                <groupId>org.projectlombok</groupId>
                <artifactId>lombok</artifactId>
                <version>1.18.12</version>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-test</artifactId>
                <scope>test</scope>
                <exclusions>
                    <exclusion>
                        <groupId>org.junit.vintage</groupId>
                        <artifactId>junit-vintage-engine</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>
        </dependencies>
    
        <build>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                </plugin>
            </plugins>
        </build>
    
    </project>
    

    由于web依赖是后加的,所以没有默认resources下没有默认生成的文件夹,要自己创建。

    注意:在不导入jdbc的情况下,程序可以正常运行,暂时猜测是springboot这个版本的mybatis里面集成了jdbc。

    3、配置properties或yml文件

    3.1、properties版本

    spring.datasource.username=root
    spring.datasource.password=123456
    spring.datasource.url=jdbc:mysql://localhost:3306/mybatis?useUnicode=true&characterEncoding=utf-8
    spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
    
    # 整合mybatis
    mybatis.type-aliases-package=com.fan.pojo
    mybatis.mapper-locations=classpath:mybatis/mapper/*.xml
    

    3.2、yml版本

    spring:
      datasource:
        username: root
        password: 123456
        #?serverTimezone=UTC解决时区的报错
        url: jdbc:mysql://localhost:3306/springboot?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8
        driver-class-name: com.mysql.cj.jdbc.Driver
    

    4、在IDEA中连接数据库

    然后按提示来就好了,这一步如果不清楚,可以百度,相关的博客很多。

    5、创建实体类

    package com.fan.pojo;
    
    import lombok.AllArgsConstructor;
    import lombok.Data;
    import lombok.NoArgsConstructor;
    
    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    public class Person {
    
        private int id;
        private String name;
        private int gender;
        private String book;
    
    }
    

    6、创建mapper文件

    6.1、创建PersonMapper接口

    package com.fan.mapper;
    
    import com.fan.pojo.Person;
    import org.apache.ibatis.annotations.Mapper;
    import org.springframework.stereotype.Repository;
    
    import java.util.List;
    
    @Mapper
    @Repository
    public interface PersonMapper {
    
        List<Person> queryPersonList();
    
        Person queryPersonById(int id);
    
        int addPerson(Person person);
    
        int updatePerson(Person person);
    
        int deletePerson(int id);
    
    }
    

    6.2、编写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="com.fan.mapper.PersonMapper">
        <select id="queryPersonList" resultType="Person">
            select * from mybatis.person;
        </select>
    
        <select id="queryPersonById" resultType="Person">
            select * from mybatis.person where id = #{id};
        </select>
    
        <insert id="addPerson" parameterType="Person">
            insert into mybatis.person (name, gender, book) values (#{name}, #{gender}, #{book});
        </insert>
    
        <update id="updatePerson" parameterType="Person">
            update mybatis.person set name=#{name}, gender=#{gender}, book=#{book} where id=#{id};
        </update>
    
        <delete id="deletePerson" parameterType="int">
            delete from mybatis.person where id=#{id};
        </delete>
    
    </mapper>
    

    7、测试

    package com.fan;
    
    import com.fan.mapper.PersonMapper;
    import com.fan.pojo.Person;
    import org.junit.jupiter.api.Test;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.boot.test.context.SpringBootTest;
    
    import java.util.List;
    
    @SpringBootTest
    class SpringbootMybatisApplicationTests {
    
        @Autowired
        private PersonMapper personMapper;
    
        @Test
        void contextLoads() {
    
            System.out.println("======1======");
    
            List<Person> people = personMapper.queryPersonList();
            for (Person personTmp : people) {
                System.out.println(personTmp);
            }
    
            System.out.println("=====2======");
    
            Person person = personMapper.queryPersonById(2);
            System.out.println(person);
    
            System.out.println("======3======");
            Person person1 = new Person(0, "谢晓峰", 1, "《三少爷的剑》");
            personMapper.addPerson(person1);
            people = personMapper.queryPersonList();
            for (Person personTmp : people) {
                System.out.println(personTmp);
            }
    
            System.out.println("======4======");
            Person person2 = new Person(2, "胡斐", 1, "《飞狐外传》");
            personMapper.updatePerson(person2);
            people = personMapper.queryPersonList();
            for (Person personTmp : people) {
                System.out.println(personTmp);
            }
    
            System.out.println("======5======");
            personMapper.deletePerson(9);
            people = personMapper.queryPersonList();
            for (Person personTmp : people) {
                System.out.println(personTmp);
            }
        }
    
    }
    

    控制台输出:

    "C:Program FilesJavajdk-13.0.1injava.exe" -ea "-javaagent:E:Program FilesJetBrainsIntelliJ IDEA 2019.3.1libidea_rt.jar=7302:E:Program FilesJetBrainsIntelliJ IDEA 2019.3.1in" -Dfile.encoding=UTF-8 -classpath "E:Program FilesJetBrainsIntelliJ IDEA 2019.3.1libidea_rt.jar;E:Program FilesJetBrainsIntelliJ IDEA 2019.3.1pluginsjunitlibjunit5-rt.jar;E:Program FilesJetBrainsIntelliJ IDEA 2019.3.1pluginsjunitlibjunit-rt.jar;E:Users19833IdeaProjectsspringboot-mybatis	arget	est-classes;E:Users19833IdeaProjectsspringboot-mybatis	argetclasses;E:Javamy_maven_repositorymaven_repositoryorgspringframeworkootspring-boot-starter2.3.3.RELEASEspring-boot-starter-2.3.3.RELEASE.jar;E:Javamy_maven_repositorymaven_repositoryorgspringframeworkootspring-boot2.3.3.RELEASEspring-boot-2.3.3.RELEASE.jar;E:Javamy_maven_repositorymaven_repositoryorgspringframeworkspring-context5.2.8.RELEASEspring-context-5.2.8.RELEASE.jar;E:Javamy_maven_repositorymaven_repositoryorgspringframeworkootspring-boot-autoconfigure2.3.3.RELEASEspring-boot-autoconfigure-2.3.3.RELEASE.jar;E:Javamy_maven_repositorymaven_repositoryorgspringframeworkootspring-boot-starter-logging2.3.3.RELEASEspring-boot-starter-logging-2.3.3.RELEASE.jar;E:Javamy_maven_repositorymaven_repositorychqoslogbacklogback-classic1.2.3logback-classic-1.2.3.jar;E:Javamy_maven_repositorymaven_repositorychqoslogbacklogback-core1.2.3logback-core-1.2.3.jar;E:Javamy_maven_repositorymaven_repositoryorgapachelogginglog4jlog4j-to-slf4j2.13.3log4j-to-slf4j-2.13.3.jar;E:Javamy_maven_repositorymaven_repositoryorgapachelogginglog4jlog4j-api2.13.3log4j-api-2.13.3.jar;E:Javamy_maven_repositorymaven_repositoryorgslf4jjul-to-slf4j1.7.30jul-to-slf4j-1.7.30.jar;E:Javamy_maven_repositorymaven_repositoryjakartaannotationjakarta.annotation-api1.3.5jakarta.annotation-api-1.3.5.jar;E:Javamy_maven_repositorymaven_repositoryorgspringframeworkspring-core5.2.8.RELEASEspring-core-5.2.8.RELEASE.jar;E:Javamy_maven_repositorymaven_repositoryorgspringframeworkspring-jcl5.2.8.RELEASEspring-jcl-5.2.8.RELEASE.jar;E:Javamy_maven_repositorymaven_repositoryorgyamlsnakeyaml1.26snakeyaml-1.26.jar;E:Javamy_maven_repositorymaven_repositoryorgmybatisspringootmybatis-spring-boot-starter2.1.3mybatis-spring-boot-starter-2.1.3.jar;E:Javamy_maven_repositorymaven_repositoryorgmybatisspringootmybatis-spring-boot-autoconfigure2.1.3mybatis-spring-boot-autoconfigure-2.1.3.jar;E:Javamy_maven_repositorymaven_repositoryorgmybatismybatis3.5.5mybatis-3.5.5.jar;E:Javamy_maven_repositorymaven_repositoryorgmybatismybatis-spring2.0.5mybatis-spring-2.0.5.jar;E:Javamy_maven_repositorymaven_repositoryorgspringframeworkootspring-boot-starter-jdbc2.3.3.RELEASEspring-boot-starter-jdbc-2.3.3.RELEASE.jar;E:Javamy_maven_repositorymaven_repositorycomzaxxerHikariCP3.4.5HikariCP-3.4.5.jar;E:Javamy_maven_repositorymaven_repositoryorgslf4jslf4j-api1.7.30slf4j-api-1.7.30.jar;E:Javamy_maven_repositorymaven_repositoryorgspringframeworkspring-jdbc5.2.8.RELEASEspring-jdbc-5.2.8.RELEASE.jar;E:Javamy_maven_repositorymaven_repositoryorgspringframeworkspring-beans5.2.8.RELEASEspring-beans-5.2.8.RELEASE.jar;E:Javamy_maven_repositorymaven_repositoryorgspringframeworkspring-tx5.2.8.RELEASEspring-tx-5.2.8.RELEASE.jar;E:Javamy_maven_repositorymaven_repositoryorgspringframeworkootspring-boot-starter-web2.3.3.RELEASEspring-boot-starter-web-2.3.3.RELEASE.jar;E:Javamy_maven_repositorymaven_repositoryorgspringframeworkootspring-boot-starter-json2.3.3.RELEASEspring-boot-starter-json-2.3.3.RELEASE.jar;E:Javamy_maven_repositorymaven_repositorycomfasterxmljacksoncorejackson-databind2.11.2jackson-databind-2.11.2.jar;E:Javamy_maven_repositorymaven_repositorycomfasterxmljacksoncorejackson-annotations2.11.2jackson-annotations-2.11.2.jar;E:Javamy_maven_repositorymaven_repositorycomfasterxmljacksoncorejackson-core2.11.2jackson-core-2.11.2.jar;E:Javamy_maven_repositorymaven_repositorycomfasterxmljacksondatatypejackson-datatype-jdk82.11.2jackson-datatype-jdk8-2.11.2.jar;E:Javamy_maven_repositorymaven_repositorycomfasterxmljacksondatatypejackson-datatype-jsr3102.11.2jackson-datatype-jsr310-2.11.2.jar;E:Javamy_maven_repositorymaven_repositorycomfasterxmljacksonmodulejackson-module-parameter-names2.11.2jackson-module-parameter-names-2.11.2.jar;E:Javamy_maven_repositorymaven_repositoryorgspringframeworkootspring-boot-starter-tomcat2.3.3.RELEASEspring-boot-starter-tomcat-2.3.3.RELEASE.jar;E:Javamy_maven_repositorymaven_repositoryorgapache	omcatembed	omcat-embed-core9.0.37	omcat-embed-core-9.0.37.jar;E:Javamy_maven_repositorymaven_repositoryorgglassfishjakarta.el3.0.3jakarta.el-3.0.3.jar;E:Javamy_maven_repositorymaven_repositoryorgapache	omcatembed	omcat-embed-websocket9.0.37	omcat-embed-websocket-9.0.37.jar;E:Javamy_maven_repositorymaven_repositoryorgspringframeworkspring-web5.2.8.RELEASEspring-web-5.2.8.RELEASE.jar;E:Javamy_maven_repositorymaven_repositoryorgspringframeworkspring-webmvc5.2.8.RELEASEspring-webmvc-5.2.8.RELEASE.jar;E:Javamy_maven_repositorymaven_repositoryorgspringframeworkspring-aop5.2.8.RELEASEspring-aop-5.2.8.RELEASE.jar;E:Javamy_maven_repositorymaven_repositoryorgspringframeworkspring-expression5.2.8.RELEASEspring-expression-5.2.8.RELEASE.jar;E:Javamy_maven_repositorymaven_repositorymysqlmysql-connector-java8.0.21mysql-connector-java-8.0.21.jar;E:Javamy_maven_repositorymaven_repositoryorgprojectlomboklombok1.18.12lombok-1.18.12.jar;E:Javamy_maven_repositorymaven_repositoryorgspringframeworkootspring-boot-starter-test2.3.3.RELEASEspring-boot-starter-test-2.3.3.RELEASE.jar;E:Javamy_maven_repositorymaven_repositoryorgspringframeworkootspring-boot-test2.3.3.RELEASEspring-boot-test-2.3.3.RELEASE.jar;E:Javamy_maven_repositorymaven_repositoryorgspringframeworkootspring-boot-test-autoconfigure2.3.3.RELEASEspring-boot-test-autoconfigure-2.3.3.RELEASE.jar;E:Javamy_maven_repositorymaven_repositorycomjaywayjsonpathjson-path2.4.0json-path-2.4.0.jar;E:Javamy_maven_repositorymaven_repository
    etminidevjson-smart2.3json-smart-2.3.jar;E:Javamy_maven_repositorymaven_repository
    etminidevaccessors-smart1.2accessors-smart-1.2.jar;E:Javamy_maven_repositorymaven_repositoryorgow2asmasm5.0.4asm-5.0.4.jar;E:Javamy_maven_repositorymaven_repositoryjakartaxmlindjakarta.xml.bind-api2.3.3jakarta.xml.bind-api-2.3.3.jar;E:Javamy_maven_repositorymaven_repositoryjakartaactivationjakarta.activation-api1.2.2jakarta.activation-api-1.2.2.jar;E:Javamy_maven_repositorymaven_repositoryorgassertjassertj-core3.16.1assertj-core-3.16.1.jar;E:Javamy_maven_repositorymaven_repositoryorghamcresthamcrest2.2hamcrest-2.2.jar;E:Javamy_maven_repositorymaven_repositoryorgjunitjupiterjunit-jupiter5.6.2junit-jupiter-5.6.2.jar;E:Javamy_maven_repositorymaven_repositoryorgjunitjupiterjunit-jupiter-api5.6.2junit-jupiter-api-5.6.2.jar;E:Javamy_maven_repositorymaven_repositoryorgapiguardianapiguardian-api1.1.0apiguardian-api-1.1.0.jar;E:Javamy_maven_repositorymaven_repositoryorgopentest4jopentest4j1.2.0opentest4j-1.2.0.jar;E:Javamy_maven_repositorymaven_repositoryorgjunitplatformjunit-platform-commons1.6.2junit-platform-commons-1.6.2.jar;E:Javamy_maven_repositorymaven_repositoryorgjunitjupiterjunit-jupiter-params5.6.2junit-jupiter-params-5.6.2.jar;E:Javamy_maven_repositorymaven_repositoryorgjunitjupiterjunit-jupiter-engine5.6.2junit-jupiter-engine-5.6.2.jar;E:Javamy_maven_repositorymaven_repositoryorgjunitplatformjunit-platform-engine1.6.2junit-platform-engine-1.6.2.jar;E:Javamy_maven_repositorymaven_repositoryorgmockitomockito-core3.3.3mockito-core-3.3.3.jar;E:Javamy_maven_repositorymaven_repository
    etytebuddyyte-buddy1.10.14yte-buddy-1.10.14.jar;E:Javamy_maven_repositorymaven_repository
    etytebuddyyte-buddy-agent1.10.14yte-buddy-agent-1.10.14.jar;E:Javamy_maven_repositorymaven_repositoryorgobjenesisobjenesis2.6objenesis-2.6.jar;E:Javamy_maven_repositorymaven_repositoryorgmockitomockito-junit-jupiter3.3.3mockito-junit-jupiter-3.3.3.jar;E:Javamy_maven_repositorymaven_repositoryorgskyscreamerjsonassert1.5.0jsonassert-1.5.0.jar;E:Javamy_maven_repositorymaven_repositorycomvaadinexternalgoogleandroid-json.0.20131108.vaadin1android-json-0.0.20131108.vaadin1.jar;E:Javamy_maven_repositorymaven_repositoryorgspringframeworkspring-test5.2.8.RELEASEspring-test-5.2.8.RELEASE.jar;E:Javamy_maven_repositorymaven_repositoryorgxmlunitxmlunit-core2.7.0xmlunit-core-2.7.0.jar;E:Javamy_maven_repositorymaven_repositoryorgjunitplatformjunit-platform-launcher1.6.2junit-platform-launcher-1.6.2.jar" com.intellij.rt.junit.JUnitStarter -ideVersion5 -junit5 com.fan.SpringbootMybatisApplicationTests,contextLoads
    15:30:54.915 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating CacheAwareContextLoaderDelegate from class [org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate]
    15:30:54.959 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating BootstrapContext using constructor [public org.springframework.test.context.support.DefaultBootstrapContext(java.lang.Class,org.springframework.test.context.CacheAwareContextLoaderDelegate)]
    15:30:55.072 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating TestContextBootstrapper for test class [com.fan.SpringbootMybatisApplicationTests] from class [org.springframework.boot.test.context.SpringBootTestContextBootstrapper]
    15:30:55.122 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Neither @ContextConfiguration nor @ContextHierarchy found for test class [com.fan.SpringbootMybatisApplicationTests], using SpringBootContextLoader
    15:30:55.136 [main] DEBUG org.springframework.test.context.support.AbstractContextLoader - Did not detect default resource location for test class [com.fan.SpringbootMybatisApplicationTests]: class path resource [com/fan/SpringbootMybatisApplicationTests-context.xml] does not exist
    15:30:55.137 [main] DEBUG org.springframework.test.context.support.AbstractContextLoader - Did not detect default resource location for test class [com.fan.SpringbootMybatisApplicationTests]: class path resource [com/fan/SpringbootMybatisApplicationTestsContext.groovy] does not exist
    15:30:55.139 [main] INFO org.springframework.test.context.support.AbstractContextLoader - Could not detect default resource locations for test class [com.fan.SpringbootMybatisApplicationTests]: no resource found for suffixes {-context.xml, Context.groovy}.
    15:30:55.141 [main] INFO org.springframework.test.context.support.AnnotationConfigContextLoaderUtils - Could not detect default configuration classes for test class [com.fan.SpringbootMybatisApplicationTests]: SpringbootMybatisApplicationTests does not declare any static, non-private, non-final, nested classes annotated with @Configuration.
    15:30:55.274 [main] DEBUG org.springframework.test.context.support.ActiveProfilesUtils - Could not find an 'annotation declaring class' for annotation type [org.springframework.test.context.ActiveProfiles] and class [com.fan.SpringbootMybatisApplicationTests]
    15:30:55.485 [main] DEBUG org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider - Identified candidate component class: file [E:Users19833IdeaProjectsspringboot-mybatis	argetclassescomfanSpringbootMybatisApplication.class]
    15:30:55.488 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Found @SpringBootConfiguration com.fan.SpringbootMybatisApplication for test class com.fan.SpringbootMybatisApplicationTests
    15:30:55.811 [main] DEBUG org.springframework.boot.test.context.SpringBootTestContextBootstrapper - @TestExecutionListeners is not present for class [com.fan.SpringbootMybatisApplicationTests]: using defaults.
    15:30:55.812 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Loaded default TestExecutionListener class names from location [META-INF/spring.factories]: [org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener, org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener, org.springframework.boot.test.autoconfigure.webservices.client.MockWebServiceServerTestExecutionListener, org.springframework.test.context.web.ServletTestExecutionListener, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener, org.springframework.test.context.support.DependencyInjectionTestExecutionListener, org.springframework.test.context.support.DirtiesContextTestExecutionListener, org.springframework.test.context.transaction.TransactionalTestExecutionListener, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener, org.springframework.test.context.event.EventPublishingTestExecutionListener]
    15:30:55.870 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Using TestExecutionListeners: [org.springframework.test.context.web.ServletTestExecutionListener@205d38da, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener@6950ed69, org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener@6dd7b5a3, org.springframework.boot.test.autoconfigure.SpringBootDependencyInjectionTestExecutionListener@6f3187b0, org.springframework.test.context.support.DirtiesContextTestExecutionListener@2663e964, org.springframework.test.context.transaction.TransactionalTestExecutionListener@48b67364, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener@189cbd7c, org.springframework.test.context.event.EventPublishingTestExecutionListener@7bf3a5d8, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener@42e25b0b, org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener@39b43d60, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener@44be0077, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener@2205a05d, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener@72ef8d15, org.springframework.boot.test.autoconfigure.webservices.client.MockWebServiceServerTestExecutionListener@6aa8e115]
    15:30:55.891 [main] DEBUG org.springframework.test.context.support.AbstractDirtiesContextTestExecutionListener - Before test class: context [DefaultTestContext@64e7619d testClass = SpringbootMybatisApplicationTests, testInstance = [null], testMethod = [null], testException = [null], mergedContextConfiguration = [WebMergedContextConfiguration@495ee280 testClass = SpringbootMybatisApplicationTests, locations = '{}', classes = '{class com.fan.SpringbootMybatisApplication}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true}', contextCustomizers = set[org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@489115ef, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@7c6908d7, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.web.client.TestRestTemplateContextCustomizer@45c7e403, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@0, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizerFactory$Customizer@2de23121, org.springframework.boot.test.context.SpringBootTestArgs@1], resourceBasePath = 'src/main/webapp', contextLoader = 'org.springframework.boot.test.context.SpringBootContextLoader', parent = [null]], attributes = map['org.springframework.test.context.web.ServletTestExecutionListener.activateListener' -> true]], class annotated with @DirtiesContext [false] with mode [null].
    15:30:55.989 [main] DEBUG org.springframework.test.context.support.TestPropertySourceUtils - Adding inlined properties to environment: {spring.jmx.enabled=false, org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true}
    
      .   ____          _            __ _ _
     /\ / ___'_ __ _ _(_)_ __  __ _    
    ( ( )\___ | '_ | '_| | '_ / _` |    
     \/  ___)| |_)| | | | | || (_| |  ) ) ) )
      '  |____| .__|_| |_|_| |_\__, | / / / /
     =========|_|==============|___/=/_/_/_/
     :: Spring Boot ::        (v2.3.3.RELEASE)
    
    2020-09-11 15:30:56.938  INFO 6472 --- [           main] c.fan.SpringbootMybatisApplicationTests  : Starting SpringbootMybatisApplicationTests on LAPTOP-B5VI5EAL with PID 6472 (started by 19833 in E:Users19833IdeaProjectsspringboot-mybatis)
    2020-09-11 15:30:56.943  INFO 6472 --- [           main] c.fan.SpringbootMybatisApplicationTests  : No active profile set, falling back to default profiles: default
    2020-09-11 15:31:00.994  INFO 6472 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
    2020-09-11 15:31:03.218  INFO 6472 --- [           main] c.fan.SpringbootMybatisApplicationTests  : Started SpringbootMybatisApplicationTests in 7.19 seconds (JVM running for 10.818)
    
    ======1======
    2020-09-11 15:31:04.796  INFO 6472 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
    2020-09-11 15:31:14.078  INFO 6472 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
    Person(id=1, name=孙小红, gender=0, book=《小李飞刀》)
    Person(id=2, name=胡斐, gender=1, book=《雪山飞狐》)
    Person(id=3, name=梅吟雪, gender=0, book=《护花铃》)
    Person(id=4, name=南宫平, gender=1, book=《护花铃》)
    Person(id=5, name=令狐冲, gender=1, book=《笑傲江湖》)
    Person(id=6, name=俞佩玉, gender=1, book=《名剑风流》)
    Person(id=7, name=杨过, gender=1, book=《神雕侠侣》)
    Person(id=8, name=谢晓峰, gender=1, book=《三少爷的剑》)
    =====2======
    Person(id=2, name=胡斐, gender=1, book=《雪山飞狐》)
    ======3======
    Person(id=1, name=孙小红, gender=0, book=《小李飞刀》)
    Person(id=2, name=胡斐, gender=1, book=《雪山飞狐》)
    Person(id=3, name=梅吟雪, gender=0, book=《护花铃》)
    Person(id=4, name=南宫平, gender=1, book=《护花铃》)
    Person(id=5, name=令狐冲, gender=1, book=《笑傲江湖》)
    Person(id=6, name=俞佩玉, gender=1, book=《名剑风流》)
    Person(id=7, name=杨过, gender=1, book=《神雕侠侣》)
    Person(id=8, name=谢晓峰, gender=1, book=《三少爷的剑》)
    Person(id=9, name=谢晓峰, gender=1, book=《三少爷的剑》)
    ======4======
    Person(id=1, name=孙小红, gender=0, book=《小李飞刀》)
    Person(id=2, name=胡斐, gender=1, book=《飞狐外传》)
    Person(id=3, name=梅吟雪, gender=0, book=《护花铃》)
    Person(id=4, name=南宫平, gender=1, book=《护花铃》)
    Person(id=5, name=令狐冲, gender=1, book=《笑傲江湖》)
    Person(id=6, name=俞佩玉, gender=1, book=《名剑风流》)
    Person(id=7, name=杨过, gender=1, book=《神雕侠侣》)
    Person(id=8, name=谢晓峰, gender=1, book=《三少爷的剑》)
    Person(id=9, name=谢晓峰, gender=1, book=《三少爷的剑》)
    ======5======
    Person(id=1, name=孙小红, gender=0, book=《小李飞刀》)
    Person(id=2, name=胡斐, gender=1, book=《飞狐外传》)
    Person(id=3, name=梅吟雪, gender=0, book=《护花铃》)
    Person(id=4, name=南宫平, gender=1, book=《护花铃》)
    Person(id=5, name=令狐冲, gender=1, book=《笑傲江湖》)
    Person(id=6, name=俞佩玉, gender=1, book=《名剑风流》)
    Person(id=7, name=杨过, gender=1, book=《神雕侠侣》)
    Person(id=8, name=谢晓峰, gender=1, book=《三少爷的剑》)
    
    2020-09-11 15:31:14.435  INFO 6472 --- [extShutdownHook] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown initiated...
    2020-09-11 15:31:14.504  INFO 6472 --- [extShutdownHook] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown completed.
    2020-09-11 15:31:14.507  INFO 6472 --- [extShutdownHook] o.s.s.concurrent.ThreadPoolTaskExecutor  : Shutting down ExecutorService 'applicationTaskExecutor'
    
    Process finished with exit code 0
    

    这里的测试并没有用到web,不过也可以尝试一下,写一个Controller就好,然后直接把数据传到网页上。

    8、这个项目初始框架存放地址

    码云(待传):~

  • 相关阅读:
    自定义标签的作用
    自定义标签处理器类的生命周期
    自定义标签的执行过程
    自定义标签入门案例
    JSTL核心标签库详解
    JSTL标签(核心标准库)
    动作标签
    jsp标签
    EL表达式
    JSP学习案例--,竞猜游戏
  • 原文地址:https://www.cnblogs.com/fanlumaster/p/13652083.html
Copyright © 2011-2022 走看看