如何在SpringBoot中集成MyBatis

本文主要讲解如何在Springboot中逐步实现对mybatis的集成应用。

1、引入依赖

在pom.xml文件中引入mybatis依赖

// pom.xml
 
<dependency>
    <groupId>org.mybatis.spring.boot</groupId>
    <artifactId>mybatis-spring-boot-starter</artifactId>
</dependency>

2、参数配置

mybatis:
  mapper-locations: classpath:mybatis/mapper/**/*.xml  #注意:一定要对应mapper映射xml文件的所在路径
  type-aliases-package: com.knight.ygtcloud.base.entity  # 注意:对应实体类的路径
  # spring boot集成mybatis的方式打印sql
  configuration:
    log-impl: org.apache.ibatis.logging.nologging.NoLoggingImpl #不打印SQL
    map-underscore-to-camel-case: true #开启自动下划线格式转驼峰格式
3、mapper文件

编写mapper文件如下:

public interface SysUserMapper {
    int deleteByPrimaryKey(Long id);
 
    int insert(SysUser record);
 
    int insertSelective(SysUser record);
 
    SysUser selectByPrimaryKey(Long id);
 
    int updateByPrimaryKeySelective(SysUser record);
 
    int updateByPrimaryKey(SysUser record);
}
🔒 点击解锁完整内容


次阅读

扫描下方二维码,关注公众号:程序进阶之路,实时获取更多优质文章推送。


扫码关注

评论