首页 > 编程语言 > 详细

SpringBoot 中MyBatis的配置

时间:2020-03-25 15:43:44      阅读:56      评论:0      收藏:0      [点我收藏+]

经实践,分享两种配置方法:

方法一:使用类中加注解@Mapper

 

import com.gjq.admin.demo.domain.pri.SysMenu;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
import java.util.Map;

@Mapper
public interface SysMenuMapper {
    int deleteByPrimaryKey(Long menuId);
    int insert(SysMenu record);
    int insertSelective(SysMenu record);
    SysMenu selectByPrimaryKey(Long menuId);
    int updateByPrimaryKeySelective(SysMenu record);
    int updateByPrimaryKey(SysMenu record);
}

 

然后在配置文件中配置xml路径,我的XML是放在resources=>mapper下面

在application.yml中配置 如下:

 

mybatis :
  mapper-locations : classpath:mapper/pri/*.xml

 

----------------------------------------------------------------------------------------------------------------------------------------------------------------------

方法二:在启动类使用:@MapperScan

@SpringBootApplication
@MapperScan("com.gjq.admin.demo.mapper.pri")
public class AdminDemoApplication {
    public static void main(String[] args) {
        SpringApplication.run(AdminDemoApplication.class, args);
    }
}

在application.yml中配置 如下:

 

mybatis :
  mapper-locations : classpath:mapper/pri/*.xml

 

SpringBoot 中MyBatis的配置

原文:https://www.cnblogs.com/gjq1126-web/p/12566127.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!