当前位置:首页 >> 跨学科知识体系 >> 【SpringBoot】配置文件,miui v4

【SpringBoot】配置文件,miui v4

cpugpu芯片开发光刻机 跨学科知识体系 1
文件名:【SpringBoot】配置文件,miui v4 【SpringBoot】配置文件

配置文件官网

1. 配置方式 application.propertiesapplication.yml / application.yaml 2. 自定义配置信息

将实体类中的本应该写死的信息写在属性配置文件中。

可以使用 @Value("${键名}") 获取,也可以使用 @ConfigurationProperties(prefix="前缀") 获取(实体类成员变量名与配置文件中的键名保持一致)。

// pojopackage com.itheima.springbootconfigfile.pojo;import org.springframework.beans.factory.annotation.Value;import org.springframework.boot.context.properties.ConfigurationProperties;import org.springframework.stereotype.Component;@Component@ConfigurationProperties(prefix = "email")public class EmailProperties {//@Value("${email.user}")//发件人邮箱public String user ;//@Value("${email.code}")//发件人邮箱授权码public String code ;//@Value("${email.host}")//发件人邮箱对应的服务器域名,如果是163邮箱:smtp.163.com qq邮箱: smtp.qq.compublic String host ;//@Value("${email.auth}")//身份验证开关private boolean auth ;public String getHost() {return host;}public void setHost(String host) {this.host = host;}public boolean isAuth() {return auth;}public void setAuth(boolean auth) {this.auth = auth;}public String getUser() {return user;}public void setUser(String user) {this.user = user;}public String getCode() {return code;}public void setCode(String code) {this.code = code;}@Overridepublic String toString() {return "EmailProperties{" +"host='" + host + '\'' +", auth=" + auth +", user='" + user + '\'' +", code='" + code + '\'' +'}';}} # application.yml#发件人相关的信息email:user: 593140521@qq.comcode: jfejwezhcrzcbbbbhost: smtp.qq.comauth: true#学生的爱好 数组hobbies:- 打篮球- 打豆豆- 打游戏
协助本站SEO优化一下,谢谢!
关键词不能为空
同类推荐
«    2025年12月    »
1234567
891011121314
15161718192021
22232425262728
293031
控制面板
您好,欢迎到访网站!
  查看权限
网站分类
搜索
最新留言
文章归档
网站收藏
友情链接