SpingBoot整合Mybatis

论坛 期权论坛 编程之家     
选择匿名的用户   2021-6-2 15:47   2935   0

1.依赖


        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>1.1.1</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

2. 配置文件

spring:
  datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://127.0.0.1/sunlin3?autoReconnect=true&useUnicode=true&characterEncoding=UTF8&useSSL=false&serverTimezone=Asia/Shanghai
    username: root
    password: 123456

mybatis:
  mapper-locations: classpath:mapper/*Mapper.xml
  configuration:
    # 开启自动驼峰命名
    map-underscore-to-camel-case: true
  # 实体类路径,开启自动别名映射
  type-aliases-package: com.labelwall.commodity

3. 主类

// dao层的包路径
@MapperScan("com.labelwall.commodity.mapper")
@SpringBootApplication
public class BusinessCommodityApplication {

    public static void main(String[] args) {
        SpringApplication.run(BusinessCommodityApplication.class, args);
    }

}

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP