zoukankan      html  css  js  c++  java
  • SpringBoot整合MyBatis

    使用方法

    1: 添加依赖 mybatis

    <!--springBoot整合Mybatis依赖-->
    <dependency>
    <groupId>org.mybatis.spring.boot</groupId>
    <artifactId>mybatis-spring-boot-starter</artifactId>
    <version>1.1.1</version>
    </dependency>

    2:在配置文件中配置数据源信息(这里使用的是后缀名yaml配置文件)

    spring:
      datasource:
        driver-class-name: com.mysql.jdbc.Driver
        url: jdbc:mysql://127.0.0.1:3306/springboot
        username: root
        password: ROOT

    3:编写pojo mapper接口 mapeer映射文件

    4:手动配置mybatis的包扫描 

        在主启动类添加@MapperScan

    5.错误:org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.offcn.mapper.UserMapper.getUserList

     把映射文件 放到resources 目录下 结构目录一模一样

    需要在pom.xml文件中配置,如果将mapper映射文件中放在java目录中,是不能够编译的,配置这个的目的就是将java下的mapper映射文件放在resources目录下

    <build>
            <!--由于java目录下的xml文件,不能够被编译,因此这里的意思就是将java目录下xml放在resources下-->
            <resources>
                <resource>
                    <directory>src/main/java</directory>
                    <includes>
                        <include>**/*.properties</include>
                        <include>**/*.xml</include>
                    </includes>
                    <filtering>false</filtering>
                </resource>
                <resource>
                    <directory>src/main/resources</directory>
                    <includes>
                        <include>**/*.*</include>
                    </includes>
                    <filtering>false</filtering>
                </resource>
            </resources>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                </plugin>
            </plugins>
        </build>

     

     

     

     

     

     

     

  • 相关阅读:
    寒假学习10
    寒假学习9
    寒假学习8
    寒假学期7
    寒假学习6
    寒假学习5
    寒假学习4
    Notification通知栏的使用
    Service的使用
    BroadcastReceive的使用
  • 原文地址:https://www.cnblogs.com/lqcswy/p/11798827.html
Copyright © 2011-2022 走看看