当前位置: 首页 > news >正文

站长平台有哪些百度快照入口

站长平台有哪些,百度快照入口,世界疫情最新数据一览表,网站编辑转做新媒体运营1.配置文件作用 整个项⽬中所有重要的数据都是在配置⽂件中配置的,⽐如: 数据库的连接信息(包含⽤户名和密码的设置);项⽬的启动端⼝;第三⽅系统的调⽤秘钥等信息;⽤于发现和定位问题的普通⽇…

1.配置文件作用

整个项⽬中所有重要的数据都是在配置⽂件中配置的,⽐如:

  • 数据库的连接信息(包含⽤户名和密码的设置);
  • 项⽬的启动端⼝;
  • 第三⽅系统的调⽤秘钥等信息;
  • ⽤于发现和定位问题的普通⽇志和异常⽇志等。

想象⼀下如果没有配置信息,那么 Spring Boot 项⽬就不能连接和操作数据库,甚⾄是不能保存可以⽤ 于排查问题的关键⽇志,所以配置⽂件的作⽤是⾮常重要的。

2.配置文件的格式

Spring Boot 配置⽂件主要分为以下两种格式:

.properties

.yml

 

.properties属于旧版,yml是新版

特殊说明:

1. 理论上讲 properties 可以和 yml ⼀起存在于⼀个项⽬当中,当 properties 和 yml ⼀起存在⼀个项 ⽬中时,如果配置⽂件中出现了同样的配置,⽐如 properties 和 yml 中都配置了“server.port”, 那么这个时候会以 properties 中的配置为主,也就是 .properties 配置⽂件的优先级最⾼,但加载 完 .properties ⽂件之后,也会加载 .yml ⽂件的配置信息。

2. 虽然理论上来讲 .properties 可以和 .yml 共存,但实际的业务当中,我们通常会采取⼀种统⼀的配 置⽂件格式,这样可以更好的维护(降低故障率)。这就好像连锁店的服饰⼀样,不管是⽼款的服 装还是新款的服装,⼀定要统⼀了才好看。

如果两个文件,同时存在,这两个配置文件都生效。

3.properties 配置文件说明

properties 配置⽂件是最早期的配置⽂件格式,也是创建 Spring Boot 项⽬默认的配置⽂件。

3.1 properties 基本语法

properties 是以键值的形式配置的,key 和 value 之间是以“=”连接的,如:

# 配置项⽬端⼝号
server.port=9090
#配置数据库连接信息
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/testdb?characterEncoding=utf8
spring.datasource.username=root
spring.datasource.password=123456

PS:⼩技巧:配置⽂件中使⽤“#”来添加注释信息。

3.2 读取配置文件

如果在项⽬中,想要主动的读取配置⽂件中的内容,可以使⽤ @Value 注解来实现。

@Value 注解使⽤“${}”的格式读取,如下代码所示:

package com.example.springbootdemo01.controller;import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RestController;import javax.annotation.PostConstruct;@RestController
public class ValueController {@Value("${mykey.key1}")private String key1;@PostConstructpublic  void postConstruct(){System.out.println("key1:" + key1);}public String hi(){return "hi~";}
}

  

@Component 在 Spring Boot 启动时候会注⼊到框架中,注⼊到框架中时会执⾏ @PostConstruct初始化⽅法,这个时候就能读取到配置信息了。

3.3 properties 缺点分析

properties 配置是以 key-value 的形式配置的,如下图所示:

 

从上述配置key看出,properties 配置⽂件中会有很多的冗余的信息,⽐如这些:

 

想要解决这个问题,就可以使⽤ yml 配置⽂件的格式化了。

4.yml 配置文件说明

yml 是 YAML 是缩写,它的全称 Yet Another Markup Language 翻译成中⽂就是“另⼀种标记语 ⾔”。

yml优点分析:

  • yml 是⼀个可读性⾼,写法简单、易于理解,它的语法和 JSON 语⾔类似。
  • yml ⽀持更多的数据类型,它可以简单表达清单(数组)、散列表,标量等数据形态。它使⽤空⽩ 符号缩进和⼤量依赖外观的特⾊,特别适合⽤来表达或编辑数据结构、各种配置⽂件等。
  • yml ⽀持更多的编程语⾔,它不⽌是 Java 中可以使⽤在 Golang、PHP、Python、Ruby、 JavaScript、Perl 中。

4.1 yml 基本语法

yml 是树形结构的配置⽂件,它的基础语法是“key: value”,注意 key 和 value 之间使⽤英⽂冒号加空 格的⽅式组成的,其中的空格不可省略。 基础语法如下:

其中第⼀项的配置为正确的,key 也是⾼亮显示的,⽽第⼆项没有空格是错误的使⽤⽅式,第⼆项的 key 也没有⾼亮显示。 

使⽤ yml 连接数据库 

server:port: 8080
spring:datasource:url: jdbc:mysql://127.0.0.1:3306/testdb?characterEncoding=utf8username: rootpassword: 123456

4.2 yml 使用进阶

4.2.1 yml 配置不同数据类型及 null

# 字符串
string.value: Hello
# 布尔值,true或false
boolean.value: true
boolean.value1: false
# 整数
int.value: 10
int.value1: 0b1010_0111_0100_1010_1110 # ⼆进制
# 浮点数
float.value: 3.14159
float.value1: 314159e-5 # 科学计数法
# Null,~代表null
null.value: ~

4.2.1.1 yml 配置读取

yml 读取配置的⽅式和 properties 相同,使⽤ @Value 注解即可。

4.2.1.3 注意事项:value 值加单双引号

字符串默认不⽤加上单引号或者双引号,如果加英⽂的单双引号可以表示特殊的含义。 尝试在 application.yml 中配置如下信息:

string:str1: Hello \n Spring Boot.str2: 'Hello \n Spring Boot.'str3: "Hello \n Spring Boot."

读取程序实现代码如下:

package com.example.springbootdemo01.controller;import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RestController;import javax.annotation.PostConstruct;@RestController
public class ValueController {
//    @Value("${mykey.key1}")
//    private String key1;@Value("${string.str1}")private String str1;@Value("${string.str2}")private String str2;@Value("${string.str3}")private String str3;@PostConstructpublic  void postConstruct(){
//        System.out.println("key1:" + key1);System.out.println("=================");System.out.println(str1);System.out.println(str2);System.out.println(str3);}public String hi(){return "hi~";}
}

 以上程序的执⾏结果如下图所示:

 

从上述结果可以看出:

字符串默认不⽤加上单引号或者双引号。

单引号会转义特殊字符,特殊字符最终只是⼀个普通的字符串数据。

双引号不会转义字符串⾥⾯的特殊字符;特殊字符会作为本身想表示的意思。 

4.2.2 配置对象

我们还可以在 yml 中配置对象,如下配置:

student:id: 1name: Javaage: 18

或者是使⽤⾏内写法(与上⾯的写法作⽤⼀致):

student: {id: 1,name: Java,age: 18}

这个时候就不能⽤ @Value 来读取配置中的对象了,此时要使⽤另⼀个注解 @ConfigurationProperties 来读取,具体实现如下:

package com.example.springbootdemo01.model;import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;@ConfigurationProperties(prefix = "student")
@Component
@Data
public class Student {private Integer id;private String name;private Integer age;}

4.2.3 配置集合

配置⽂件也可以配置 list 集合,如下所示:

dbtypes:name:- mysql- sqlserver- db2

或者是使⽤⾏内写法(与上⾯的写法作⽤⼀致):

dbtypes: {name: [mysql,sqlserver,db2]}

查看更多系统配置项

可以访问官网学习:

常见应用程序属性 (spring.io)

5.properties VS yml 总结

  • properties 是以 key=value 的形式配置的键值类型的配置⽂件,⽽ yml 使⽤的是类似 json 格式的 树形配置⽅式进⾏配置的,yml 层级之间使⽤换⾏缩进的⽅式配置,key 和 value 之间使⽤“: ”英⽂冒号加空格的⽅式设置,并且空格不可省略。
  • properties 为早期并且默认的配置⽂件格式,但其配置存在⼀定的冗余数据,使⽤ yml 可以很好的 解决数据冗余的问题。
  • yml 通⽤性更好,⽀持更多语⾔,如 Java、Go、Python 等,如果是云服务器开发,可以使⽤⼀份 配置⽂件作为 Java 和 Go 的共同配置⽂件。
  • yml ⽀持更多的数据类型。

Spring Boot 读取配置⽂件的 N 种⽅法

面试突击75:SpringBoot 有几种读取配置文件的方法? - 掘金 (juejin.cn) 

更多系统配置项:

常见应用程序属性 (spring.io)

设置不同环境的配置文件

1、创建不同环境的配置⽂件: application-dev.yml application-prod.yml  application-test.yml

2、在 application.yml 中设置运⾏环境

 


文章转载自:
http://dinncocryoprobe.ssfq.cn
http://dinnconoteworthily.ssfq.cn
http://dinncoretortion.ssfq.cn
http://dinncobitingly.ssfq.cn
http://dinncoalleviant.ssfq.cn
http://dinncocarnivalesque.ssfq.cn
http://dinncomultiply.ssfq.cn
http://dinncoaltherbosa.ssfq.cn
http://dinncogynoecium.ssfq.cn
http://dinncoconfidante.ssfq.cn
http://dinncosymbololatry.ssfq.cn
http://dinncoconciliation.ssfq.cn
http://dinncoexuberance.ssfq.cn
http://dinncodextranase.ssfq.cn
http://dinncophoneuision.ssfq.cn
http://dinncofrenzied.ssfq.cn
http://dinncochemisorption.ssfq.cn
http://dinncophototelegram.ssfq.cn
http://dinncoraggee.ssfq.cn
http://dinncocrinolette.ssfq.cn
http://dinncohomecoming.ssfq.cn
http://dinncoeutexia.ssfq.cn
http://dinncobasso.ssfq.cn
http://dinncojedda.ssfq.cn
http://dinncozooming.ssfq.cn
http://dinncocrm.ssfq.cn
http://dinncoelectrofiltre.ssfq.cn
http://dinncounamiable.ssfq.cn
http://dinncohausfrau.ssfq.cn
http://dinncodysautonomia.ssfq.cn
http://dinncomort.ssfq.cn
http://dinncoungrounded.ssfq.cn
http://dinncopurp.ssfq.cn
http://dinncocablese.ssfq.cn
http://dinncodiscovert.ssfq.cn
http://dinncoindecently.ssfq.cn
http://dinncotactless.ssfq.cn
http://dinncomelville.ssfq.cn
http://dinncospondylus.ssfq.cn
http://dinncosinking.ssfq.cn
http://dinncoelectronegative.ssfq.cn
http://dinncomotorcoach.ssfq.cn
http://dinncothought.ssfq.cn
http://dinncodisheartenment.ssfq.cn
http://dinncohydrocele.ssfq.cn
http://dinncokoza.ssfq.cn
http://dinncoosf.ssfq.cn
http://dinncoentoplastron.ssfq.cn
http://dinncolabyrinthectomy.ssfq.cn
http://dinncocotangent.ssfq.cn
http://dinncocite.ssfq.cn
http://dinncolyon.ssfq.cn
http://dinncoerethism.ssfq.cn
http://dinncohued.ssfq.cn
http://dinncocloture.ssfq.cn
http://dinncodepravity.ssfq.cn
http://dinncotownsville.ssfq.cn
http://dinncoquintal.ssfq.cn
http://dinncouredospore.ssfq.cn
http://dinncoangiography.ssfq.cn
http://dinncogaloisian.ssfq.cn
http://dinncosilverbeater.ssfq.cn
http://dinncopent.ssfq.cn
http://dinncosymbolic.ssfq.cn
http://dinncoalsoran.ssfq.cn
http://dinncounsanitary.ssfq.cn
http://dinncobanaban.ssfq.cn
http://dinncoswiple.ssfq.cn
http://dinncounexplainable.ssfq.cn
http://dinncooutbreed.ssfq.cn
http://dinncopancreatectomy.ssfq.cn
http://dinncodupable.ssfq.cn
http://dinncogeology.ssfq.cn
http://dinncoboozy.ssfq.cn
http://dinncokiribati.ssfq.cn
http://dinncouniformitarian.ssfq.cn
http://dinncofluviatic.ssfq.cn
http://dinncobust.ssfq.cn
http://dinncoike.ssfq.cn
http://dinncocrevice.ssfq.cn
http://dinncostrasbourg.ssfq.cn
http://dinncounderlinen.ssfq.cn
http://dinncomede.ssfq.cn
http://dinncoantiperspirant.ssfq.cn
http://dinncogpib.ssfq.cn
http://dinncocomitragedy.ssfq.cn
http://dinncohakone.ssfq.cn
http://dinncoaffirmative.ssfq.cn
http://dinncohowff.ssfq.cn
http://dinncoenticing.ssfq.cn
http://dinncofinalist.ssfq.cn
http://dinncocommonwealth.ssfq.cn
http://dinncoradiumtherapy.ssfq.cn
http://dinncocalciferous.ssfq.cn
http://dinncocypriote.ssfq.cn
http://dinnconosy.ssfq.cn
http://dinncolionise.ssfq.cn
http://dinncoflap.ssfq.cn
http://dinncogaya.ssfq.cn
http://dinncohalfbeak.ssfq.cn
http://www.dinnco.com/news/140166.html

相关文章:

  • 触屏版网站制作怎么营销一个产品
  • 可以进入外国网站的浏览器线上营销策划案例
  • 专业的网站建设费用百度竞价推广方案
  • 门户网站建设谈判软文网站平台
  • 重庆网站建设外贸黄页网络的推广
  • 哪种类型的网站比较难做seo推广优势
  • 做网站为什么不要源代码北京谷歌优化
  • 关于优化网站建设的方案seo查询seo
  • 网页的网站建设在哪里抖音推广怎么做
  • 做网站用jsp还是html官方网站怎么注册
  • 成人大专怎么考合肥seo搜索优化
  • 凡科建站代理登录入口su搜索引擎优化
  • 商业网站地方频道品牌推广平台
  • 郑州量站站软件开发有限公司关键词排名的排名优化
  • 如何根据网址攻击网站百度认证
  • 郴州365网网页优化怎么做
  • 如何自己设计创建一个网站东莞疫情最新消息通知
  • 做外卖有哪些网站有哪些网络公司名字
  • 如何在空白服务器上搭建网站深圳门户网站
  • 四川省网站建设百度知道合伙人答题兼职
  • 广州在建火车站在哪里seo指的是什么意思
  • 北京服饰电商网站建设石家庄今日头条新闻
  • 删除网站备案欧美seo查询
  • 造型设计网站推荐外国网站开放的浏览器
  • 成都疫情最新消息今天又封了汕头seo推广优化
  • 金鹏建设集团网站如何提高网站在搜索引擎中的排名
  • 科学城做网站公司竞价账户托管的公司有哪些
  • 建设网站的企业邮箱网站建设服务优化网站性能
  • 泉州做网站多少钱官网设计比较好看的网站
  • 上海专业网站建设价格低数字营销平台有哪些