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框架
  • SpringBoot整合MyBatis开发框架
  • SpringBoot如何整合MyBatis?
  • spring boot整合mysql和mybatis
  • Spring boot集成mybatis和MySQL实现基础服务
  • springboot+mybatis+gradle
  • 热门搜索
    凤县旅游 泾县旅游 陕西旅游烹饪职业学院 杭州周边旅游 摩洛哥旅游 烟台旅游景点 章丘旅游 欣欣旅游网 中国旅游新闻网 日本旅游必去的地方