mybatis-plus整合spring

2021-03-05 17:27

阅读:467

标签:prope   scan   span   nfa   cto   web   val   通配符   ati   

准备工作

  • JDK 8+
  • Maven

引入依赖

dependency>
    groupId>org.springframeworkgroupId>
    artifactId>spring-webmvcartifactId>
    version>5.1.6.RELEASEversion>
dependency>

dependency>
    groupId>org.springframeworkgroupId>
    artifactId>spring-jdbcartifactId>
    version>5.1.6.RELEASEversion>
dependency>

dependency>
    groupId>org.springframeworkgroupId>
    artifactId>spring-testartifactId>
    version>5.1.6.RELEASEversion>
dependency>


dependency>
    groupId>com.baomidougroupId>
    artifactId>mybatis-plusartifactId>
    version>3.1.1version>
dependency>

编写jdbc.properties

jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/mp?useSSL=false&serverTimezone=GMT%2B8
jdbc.username=root
jdbc.password=123456

在applicationContext.xml中引入jdbc.properties


context:property-placeholder location="classpath:jdbc.properties"/>

配置dataSource


bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
    property name="driverClassName" value="${jdbc.driver}"/>
    property name="url" value="${jdbc.url}"/>
    property name="username" value="${jdbc.username}"/>
    property name="password" value="${jdbc.password}"/>
bean>

配置 MapperScan


bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
    property name="basePackage" value="com.mgyboom.mapper"/>
bean>

调整 SqlSessionFactory 为 MyBatis-Plus 的 SqlSessionFactory


bean id="sqlSessionFactory" class="com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean">
    property name="dataSource" ref="dataSource"/>
    property name="typeAliasesPackage" value="com.mgyboom.pojo"/>
    
    property name="mapperLocations" value="classpath:mapper/*.xml"/>
    
bean>

代码示例

https://gitee.com/mgyboom/spring-mp

 

mybatis-plus整合spring

标签:prope   scan   span   nfa   cto   web   val   通配符   ati   

原文地址:https://www.cnblogs.com/mgyboom/p/14321798.html


评论


亲,登录后才可以留言!