springboot整合mybatis-plus
1.引入对应的依赖
< dependency>
< groupId> com.baomidou</ groupId>
< artifactId> mybatisplus-spring-boot-starter</ artifactId>
< version> ${mybatisplus-spring-boot-starter.version}</ version>
</ dependency>
< dependency>
< groupId> com.baomidou</ groupId>
< artifactId> mybatis-plus</ artifactId>
< version> ${mybatisplus.version}</ version>
</ dependency>
2.配置文件配置
mybatis-plus :
typeAliasesPackage : com.tensquare.article.pojo
global-config :
id-type : 1
db-column-underline : false
refresh-mapper : true
configuration :
map-underscore-to-camel-case : true
cache-enabled : true
lazyLoadingEnabled : true
multipleResultSetsEnabled : true
log-impl : org.apache.ibatis.logging.stdout.StdOutImpl
3.分页插件注入
import com. baomidou. mybatisplus. plugins. PaginationInterceptor;
import org. springframework. context. annotation. Bean;
import org. springframework. context. annotation. Configuration;
@Configuration
public class MyBatisPlusConfig {
@Bean
public PaginationInterceptor createPaginationInterceptor ( ) {
return new PaginationInterceptor ( ) ;
}
}
4. 主类
import org. mybatis. spring. annotation. MapperScan;
import org. springframework. boot. SpringApplication;
import org. springframework. boot. autoconfigure. SpringBootApplication;
import org. springframework. cloud. netflix. eureka. EnableEurekaClient;
import org. springframework. cloud. openfeign. EnableFeignClients;
import org. springframework. context. annotation. Bean;
@SpringBootApplication
@MapperScan ( "com.tensquare.article.dao" )
public class ArticleApplication {
public static void main ( String[ ] args) {
SpringApplication. run ( ArticleApplication. class , args) ;
}
}
使用方法
第一步 继承BaseMapper
public interface ArticleDao extends BaseMapper < User> {
}