网站首页 美食营养 游戏数码 手工爱好 生活家居 健康养生 运动户外 职场理财 情感交际 母婴教育 时尚美容 知识问答

spring boot整合mybatis框架

时间:2024-10-15 01:49:56

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框架
© 2025 小知经验
信息来自网络 所有数据仅供参考
有疑问请联系站长 site.kefu@gmail.com