spring boot整合mybatis框架

2025-05-12 08:50:07

1、推荐使用intellij idea作为开发工具,使用intellij idea创建spring boot框架,如下图所示,添加maven依赖,代码如下 <dependenc烤恤鹇灭y> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>1.3.2</version> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <scope>runtime</scope> </dependency>

spring boot整合mybatis框架

4、添加@MapperScan()注解,配置basePackages属性,代码如下@SpringBoot帆歌达缒Application@MapperScan(basePackages = "com.zuli.mapper")public class SpringBootMybatisApplication { public static void main(String[] args) { ConfigurableApplicationContext context = SpringApplication.run(SpringBootMybatisApplication.class, args); TestMapper testMapper = context.getBean(TestMapper.class); System.out.println(testMapper.test()); }}

spring boot整合mybatis框架

6、启动应用程序,调用TestMapper的test()方法,打印日志,如下图所示

spring boot整合mybatis框架
声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢