mybatisplus

mybatisplus

1.简介

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

2.特性

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

  说明:mybatisplu的特性有不少,这里这是列出来三点,由于这三点,咱们都是常常用到的。sql

3.集成配置

  1. 与spring的集成

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

    

 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     <!-- 配置sqlSessionFacotry -->
29     <bean id="sqlSessionFactory"
30         class="com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean">
31         <!-- 注入数据源 -->
32         <property name="dataSource" ref="dataSource"></property>
33         <!-- 配置mapper.xml -->
34         <property name="mapperLocations">
35             <array>
36                 <value>classpath:mapper/*Mapper.xml</value>
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     <!-- 配置扫描mapper接口的对象 -->
49     <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
50         <property name="basePackage"
51             value="com.sxt.mapper"></property>
52         <!-- <property name="basePackage"> <value> com.sxt.mapper com.bjsxt.mapper 
53             </value> </property> -->
54         <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
55     </bean>
56 
57 </beans>

    2.与springboot的集成mybatis

 引入mybatisplusstarter.app

 

    再配置yml文件:工具

 

   启动类上加扫描注解:ui

 

 

4.经常使用的注解

 

 

 

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

由于咱们有的时候须要添加一个字段知足页面需求,可是表中却又没有,这个时候咱们就可使用这个字段了。 spa

相关文章
相关标签/搜索