springboot 整合 mybatis-plus

1、环境准备

      idea 2018、mysql、jdk1.8

2、idea创建springBoot项目(网上步骤很多)

      idea创建项目时可以选择web、mybatis、mysql,这样idea会自动加载其jar包;

     但是还需要mybatis-plus的jar包:点这里提供

     项目结构:

        springboot 整合 mybatis-plus_第1张图片

3、pom.xml:



    4.0.0

    com.xsy.sbmp
    springbmp
    0.0.1-SNAPSHOT
    jar

    springbmp
    Demo project for Spring Boot

    
        org.springframework.boot
        spring-boot-starter-parent
        2.0.3.RELEASE
         
    

    
        UTF-8
        UTF-8
        1.8
    

    
        
            com.baomidou
            mybatisplus-spring-boot-starter
            1.0.2
            system
            ${basedir}/lib/mybatisplus-spring-boot-starter-1.0.2.jar
        
        
            com.baomidou
            mybatis-plus
            2.1.0
            system
            ${basedir}/lib/mybatis-plus-2.1.0.jar
        
        
            org.mybatis.spring.boot
            mybatis-spring-boot-starter
            1.3.2
        
        
            org.springframework.boot
            spring-boot-devtools
            runtime
        

        
            org.springframework.boot
            spring-boot-starter-web
        

        
            mysql
            mysql-connector-java
            runtime
        
        
            org.springframework.boot
            spring-boot-starter-test
            test
        
    
    
        
            
                org.springframework.boot
                spring-boot-maven-plugin
            
        
    

4、application.properties:

#server port
server.port=8080

#mysql datasource
spring.datasource.url=jdbc:mysql://localhost:3306/test?characterEncoding=utf8&useSSL=false
spring.datasource.username=
spring.datasource.password=
spring.datasource.driver-class-name=com.mysql.jdbc.Driver

#logger
logging.level.com.xsy.sbmp.springbmp.dao=debug

#mapper.xml location
mybatis-plus.mapper-locations=classpath*:mapper/*.xml

#entity location
mybatis-plus.type-aliases-package=com.xsy.sbmp.springbmp.entity


5、mybatisplus配置:

@Configuration
public class MybatisPlusConfig {

    @Bean
    public PaginationInterceptor paginationInterceptor(){
        PaginationInterceptor page = new PaginationInterceptor();

        //设置方言
        page.setDialectType("mysql");
        return page;
    }
}

6、创建实体类、dao接口、mapper.xml、service、serviceImpl、controller

实体类中字段和数据库字段不一致时:@TableField("");

dao接口需要: dao接口类上需要@Repository @Mapper注解

                          还需要在springBoot启动类上jiar加上注解:@MapperScan("dao路径")

mapper.xml所有文件放到 resources文件夹下,即和application.properties同目录,否则会加载不了

其他都和ssm时一样

你可能感兴趣的:(springboot 整合 mybatis-plus)