Springboot整合Mybatis,p6spy,druid

首先,贴出完整POM文件

<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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0modelVersion>
  <groupId>com.yjygroupId>
  <artifactId>IM_TestDemoartifactId>
  <packaging>warpackaging>
  <version>0.0.1-SNAPSHOTversion>
  <name>IM_TestDemo Maven Webappname>
  <url>http://maven.apache.orgurl>
  
    <parent>
        <groupId>org.springframework.bootgroupId>
        <artifactId>spring-boot-starter-parentartifactId>
        <version>1.5.10.RELEASEversion>
    parent>  

    <dependencies>
        
        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starter-webartifactId>
        dependency>

        
        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-devtoolsartifactId>
            <optional>trueoptional>
            <scope>truescope>
        dependency>

        
        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starter-log4j2artifactId>
        dependency>
        
        <dependency>
            <groupId>org.apache.tomcat.embedgroupId>
            <artifactId>tomcat-embed-jasperartifactId>
            <scope>compilescope>
        dependency>

        
        <dependency>
            <groupId>javax.servletgroupId>
            <artifactId>javax.servlet-apiartifactId>
            <scope>providedscope>
        dependency>

        
        <dependency>
            <groupId>javax.servletgroupId>
            <artifactId>jstlartifactId>
        dependency>
        
        <dependency>
            <groupId>org.mybatis.spring.bootgroupId>
            <artifactId>mybatis-spring-boot-starterartifactId>
            <version>1.3.0version>
        dependency> 
        
        <dependency>
            <groupId>mysqlgroupId>
            <artifactId>mysql-connector-javaartifactId>
        dependency> 

        
        <dependency>
            <groupId>p6spygroupId>
            <artifactId>p6spyartifactId>
            <version>2.1.4version>
        dependency>

        
        <dependency>
            <groupId>com.alibabagroupId>
            <artifactId>druidartifactId>
            <version>1.1.10version>
        dependency>

    dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.bootgroupId>
                <artifactId>spring-boot-maven-pluginartifactId>
                
                <configuration>
                
                <fork>truefork>
                configuration>
            plugin>
        plugins>
        <finalName>IM_TestDemofinalName>
    build>
project>

Springboot整合Mybatis,p6spy,druid_第1张图片

新建application.properties配置文件,配置内容如下
Springboot整合Mybatis,p6spy,druid_第2张图片

偷个懒,这里就都一起整合了,配置文件走完,下面主要贴一下控制层的代码吧,数据层和业务层和SSM没有任何区别。
Springboot整合Mybatis,p6spy,druid_第3张图片
Springboot整合Mybatis,p6spy,druid_第4张图片
好了,写完以后,运行项目,访问地址本地主机:8080 / selectAll.do
效果如下:

Springboot整合Mybatis,p6spy,druid_第5张图片
控制台输出:

这里写图片描述
P6SPY效果出来了,可以配置将SQL打印到控制台,或直接存入日志.druid就不说了,目前比较强大的数据库连接池。

你可能感兴趣的:(Java)