Spring Boot 配置文件详解:application.yml 示例(数据库、Mybatis Plus)

Spring Boot 的基本配置文件可以是 application.propertiesapplication.yml。在配置文件中,您可以包含关于应用程序的各种设置,例如服务器端口、数据库连接信息、日志记录级别、应用程序名称、缓存配置、安全配置等。

使用数据库和 Mybatis Plus 的配置文件示例

对于使用数据库和 Mybatis Plus 的应用程序,配置文件需要包括以下内容:

  1. 数据库连接信息:
spring.datasource.url=jdbc:mysql://localhost:3306/mydb
spring.datasource.username=root
spring.datasource.password=123456
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
  1. Mybatis Plus 配置:
mybatis-plus.mapper-locations=classpath:mapper/*.xml
mybatis-plus.global-config.db-config.logic-delete-value=1
mybatis-plus.global-config.db-config.logic-not-delete-value=0
  1. 其他配置信息:
spring.profiles.active=dev
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=create

说明:

  • 以上配置项将指定应用程序在开发环境中使用 MySQL 数据库,启用 Mybatis Plus,将 XML 映射器文件存储在类路径下的 mapper 目录中,并启用 SQL 语句的显示。
  • 此外,还可以指定应用程序的运行环境为 dev,并在启动时创建数据库表。

总结

本文详细介绍了 Spring Boot 配置文件 application.yml 中常用的配置项,以及如何使用 application.yml 配置数据库连接和集成 Mybatis Plus。通过本文的学习,您可以快速上手 Spring Boot 配置,并根据实际需求进行调整。

Spring Boot 配置文件详解:application.yml 示例(数据库、Mybatis Plus)

原文地址: https://www.cveoy.top/t/topic/lB7r 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录