springboot -mysql -mybatis mybatis-puls,druid结合

1.新建项目添加mysql的依赖
手动添加mybatis-puls架包
添加druid架包

package com.example.demo.config;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.baomidou.mybatisplus.plugins.PaginationInterceptor;

@Configuration
@MapperScan("com.example.demo.mapper*")
public class MybatisPlusConfig {


    /** * mybatis-plus分页插件
* 文档:http://mp.baomidou.com
*/
@Bean public PaginationInterceptor paginationInterceptor() { PaginationInterceptor paginationInterceptor = new PaginationInterceptor(); paginationInterceptor.setLocalPage(true);// 开启 PageHelper 的支持 return paginationInterceptor; } }

application.yml配置

# 驱动配置信息 
spring:
    datasource:
              type : com.alibaba.druid.pool.DruidDataSource  
              url : jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=utf-8  
              username: root  
              password : yuhaiguang
              driverClassName : com.mysql.jdbc.Driver  

#连接池的配置信息 
# initialSize=5 
# minIdle=5 
# maxActive=20 
# maxWait=60000 
# timeBetweenEvictionRunsMillis=60000 
# minEvictableIdleTimeMillis=300000 
# validationQuery=SELECT 1 FROM DUAL 
# testWhileIdle=true 
# testOnBorrow=false 
# testOnReturn=false 
# poolPreparedStatements=true 
# maxPoolPreparedStatementPerConnectionSize=20 
# filters=stat,wall,log4j 
# connectionProperties=druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000 
#mybatis
mybatis-plus:
  mapper-locations: classpath:/mapper/*Mapper.xml
  #实体扫描,多个package用逗号或者分号分隔
  typeAliasesPackage: com.example.demo.entity
  global-config:
    #主键类型 0:"数据库ID自增", 1:"用户输入ID",2:"全局唯一ID (数字类型唯一ID)", 3:"全局唯一ID UUID";
    id-type: 2
    #字段策略 0:"忽略判断",1:"非 NULL 判断"),2:"非空判断"
    field-strategy: 2
    #驼峰下划线转换
    db-column-underline: true
    #刷新mapper 调试神器
    refresh-mapper: true
    #数据库大写下划线转换
    #capital-mode: true
    #序列接口实现类配置
    #key-generator: com.baomidou.springboot.xxx
    #逻辑删除配置
    #logic-delete-value: 0
    #logic-not-delete-value: 1
    #自定义填充策略接口实现
    #meta-object-handler: com.baomidou.springboot.xxx
    #自定义SQL注入器
    #sql-injector: com.baomidou.springboot.xxx
  configuration:
    map-underscore-to-camel-case: true
    cache-enabled: false

这两个配置项完成对数据源以及mybatis的配置,
mybatis扫描实体包,扫描mapper类以及mapper的xml文件。完成这三个扫描基本就可以用了
需要源码加群 671243328

你可能感兴趣的:(springboot)