springboot 整合Mybatis 连接池 MySQL

springboot 特点是: 

1.创建项目很快,机会不需要任何设置;

2.约定大于配置,基本配置都按默认就可以很快部署,应用

3.若想修改配置,从application.xml 中写入自己的配置,系统会首先加载先写的配置,后加载默认配置;

整合mybatis   阿里连接池,Mysql 

pom.xml

    <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid-spring-boot-starter</artifactId>
            <version>1.1.10</version>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.45</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>1.3.2</version>
        </dependency>

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

第二步:

application.properties

server.port=8081
server.servlet.context-path=/sunfch
#连接池信息
spring.datasource.druid.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.druid.url=jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8
spring.datasource.druid.username=root
spring.datasource.druid.password=passW0rd
spring.datasource.druid.initial-size=5
spring.datasource.druid.max-active=20
spring.datasource.druid.min-idle=5
spring.datasource.druid.max-wait=60000
#mybatis 扫描路径
mybatis.mapper-locations=classpath:mappers/*.xml

这一步;可以启动项目测试一次,若能正常启动,证明数据库已经连接成功

项目稍后传入到GitHub上

猜你喜欢

转载自blog.csdn.net/qq_30125555/article/details/85226648