美文网首页
SpringBoot 整合Mybatis

SpringBoot 整合Mybatis

作者: 黄靠谱 | 来源:发表于2019-06-12 10:07 被阅读0次

    参考demo
    https://github.com/huangzhenshi/demo-ssm

    1. 在启动类指定MapperScan,避免在每个Dao上写@Mapper
    @SpringBootApplication
    @MapperScan("com.example.demo.ssm.dao")
    public class DemoSsmApplication {
    
        public static void main(String[] args) {
            SpringApplication.run(DemoSsmApplication.class, args);
        }
    
    }
    
    1. 配置
    mybatis.mapper-locations=classpath*:mapper/*.xml
    mybatis.type-aliases-package=com.example.demo.ssm.entity
    
    # show mybatis sql
    logging.level.com.example.demo.ssm.mapper=debug
    
    1. 依赖
        <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
            </dependency>
            <dependency>
                <groupId>org.mybatis.spring.boot</groupId>
                <artifactId>mybatis-spring-boot-starter</artifactId>
                <version>2.0.1</version>
            </dependency>
    
            <dependency>
                <groupId>mysql</groupId>
                <artifactId>mysql-connector-java</artifactId>
                <scope>runtime</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-test</artifactId>
                <scope>test</scope>
            </dependency>
    
            <dependency>
                <groupId>org.projectlombok</groupId>
                <artifactId>lombok</artifactId>
                <version>1.16.10</version>
                <scope>provided</scope>
            </dependency>
    
            <dependency>
                <groupId>com.alibaba</groupId>
                <artifactId>druid</artifactId>
                <version>1.0.25</version>
            </dependency>
    

    相关文章

      网友评论

          本文标题:SpringBoot 整合Mybatis

          本文链接:https://www.haomeiwen.com/subject/nplkfctx.html