mybatisplus

mybatisplus

1.简介

  Mybatis-Plus(简称MP)是一个 Mybatis 的增强工具,在 Mybatis 的基础上只做增强不做改变,为简化开发、提高效率而生。

2.特性

  • 无侵入:Mybatis-Plus 在 Mybatis 的基础上进行扩展,只做增强不做改变,引入 Mybatis-Plus 不会对您现有的 Mybatis 构架产生任何影响
  • 通用CRUD操作:内置通用 Mapper、通用 Service,仅仅通过少量配置即可实现单表大部分 CRUD 操作,更有强大的条件构造器,满足各类使用需求
  • 内置分页插件:基于 Mybatis 物理分页,开发者无需关心具体操作,配置好插件之后,写分页等同于普通List查询

  说明:mybatisplu的特性有很多,这里这是列出来三点,因为这三点,我们都是经常用到的。

3.集成配置

  1. 与spring的集成

              这里集成主要是application-dao.xml这个有变化,其余的和传统的ssm集成没有任何区别。

    

 1 xml version="1.0" encoding="UTF-8"?>
 2 <beans xmlns="http://www.springframework.org/schema/beans"
 3     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 4     xmlns:context="http://www.springframework.org/schema/context"
 5     xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
 6         http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd">
 7 
 8 
 9     
10     <context:property-placeholder
11         location="classpath:db.properties" system-properties-mode="FALLBACK" />
12 
13     
14     <bean id="dataSource"
15         class="com.alibaba.druid.pool.DruidDataSource">
16         
17         <property name="driverClassName" value="${driverClassName}">property>
18         <property name="url" value="${url}">property>
19         <property name="username" value="${username}">property>
20         <property name="password" value="${password}">property>
21 
22 
23         <property name="initialSize" value="${initialSize}">property>
24         <property name="maxActive" value="${maxActive}">property>
25         <property name="minIdle" value="${minIdle}">property>
26         <property name="filters" value="${filters}">property>
27     bean>
28     
29     <bean id="sqlSessionFactory"
30         class="com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean">
31         
32         <property name="dataSource" ref="dataSource">property>
33         
34         <property name="mapperLocations">
35             <array>
36                 <value>classpath:mapper/*Mapper.xmlvalue>
37             array>
38         property>
39         
40         <property name="plugins">
41             <array>
42                 
43                 <bean class="com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor">bean>
44             array>
45         property>
46     bean>
47 
48     
49     <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
50         <property name="basePackage"
51             value="com.sxt.mapper">property>
52         
54         <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory">property>
55     bean>
56 
57 beans>

    2.与springboot的集成

 引入mybatisplusstarter.

 mybatisplus_第1张图片

    再配置yml文件:

mybatisplus_第2张图片

 

   启动类上加扫描注解:

mybatisplus_第3张图片

 

 

4.常用的注解

mybatisplus_第4张图片

 

 

 

 主键注解要特别注意这个属性:

因为我们有的时候需要添加一个字段满足页面需求,但是表中却又没有,这个时候我们就可以使用这个字段了。 

 

 

  

 

 

 

 

   

你可能感兴趣的:(mybatisplus)