栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

SpringBoot-07配置文件

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

SpringBoot-07配置文件

1、properties

同传统配置文件

2、yaml

springboot推荐使用,适合以数据为中心的配置文件

2.1基本语法

  • key: value;kv之间有空格
  • 大小写敏感
  • 使用缩进表示层级关系
  • 缩进不允许使用tab,只允许空格
  • 缩进的空格数不重要,只要相同层级的元素左对齐即可
  • '#'表示注释
  • 字符串无需加引号,如果要加,’'与""表示字符串内容 会被 转义/不转义
  • 通过@ConfigurationProperties(prefix = "student")使用
  • 双引号 n 换行,单引号转义不换行

实例:

  • 对象实例
@Data
public class Person {
	
	private String userName;
	private Boolean boss;
	private Date birth;
	private Integer age;
	private Pet pet;
	private String[] interests;
	private List animal;
	private Map score;
	private Set salarys;
	private Map> allPets;
}

@Data
public class Pet {
	private String name;
	private Double weight;
}
  • yaml表示以上对象
# yaml表示以上对象
person:
  userName: zhangsan
  boss: false
  birth: 2019/12/12 20:12:33
  age: 18
  pet: 
    name: tomcat
    weight: 23.4
  interests: [篮球,游泳]
  animal: 
    - jerry
    - mario
  score:
    english: 
      first: 30
      second: 40
      third: 50
    math: [131,140,148]
    chinese: {first: 128,second: 136}
  salarys: [3999,4999.98,5999.99]
  allPets:
    sick:
      - {name: tom}
      - {name: jerry,weight: 47}
    health: [{name: mario,weight: 47}]

例2

server:
  port: 8003

spring:
  datasource:
    url: jdbc:mysql://localhost:3306/springboot-mybatisplus?serverTimezone=Asia/Shanghai&useSSL=false&useUnicode=true&characterEncoding=utf8&characterSetResults=utf8
    username: root
    password: 123456
    driver-class-name=com: mysql.cj.jdbc.Driver

  #自定义日期格式化配置
  mvc:
    format:
      date: dd/MM/yyyy

#2、mybatis-plus配置
mybatis-plus:
  #2-1 lodging 日志
  configuration:
    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
  #2-2 deleted 逻辑删除
  global-config :
    db-config:
      logic-delete-value: 1
      logic-not-delete-value: 0

#对象赋值
student:
  id: 1
  name: pige
  age: 17
  ###############布尔型
  #  happy: true
  ###############日期
  #  birth: 1998/09/09
  ###############map
  #  maps: {k1: v1,k2: v2}
  ###############list
#  lists:
#    - play
#    - music
#    - girl

#查看配置
debug: true
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/271217.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号