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

广州做网站企业网上推广app怎么做

广州做网站企业,网上推广app怎么做,商城网站页面设计,佛山疫情最新通报SpringBoot配置的文件名是固定的:application.yml application.properties YAML:以数据为中心 比Json xml更适合做配置文件 YAML语法: 1 字面量:普通值(字符串 布尔值 数字) (1) k: v (2) " "不会转义 会转义 2 对象,map(属性和值) (1)…

SpringBoot配置的文件名是固定的:application.yml  application.properties

YAML:以数据为中心 比Json  xml更适合做配置文件

YAML语法:

1 字面量:普通值(字符串 布尔值 数字)

        (1) k: v

        (2) " "不会转义  ' '会转义

2 对象,map(属性和值)

        (1) k: v  

        (2) 在下一行 写对象的属性和值

    数组(List,set)

        用 - 表示数组中的一个元素

      行内写法

 

properties配置文件容易乱码 需要在设置中找到这个然后调成这样

 示例1(在yml文件中配置):

application.yaml文件中配置

Person:name: 张三age: 21boss: truebirth: 2022/12/5maps: {key1: value1,key2: value2}list: [dog,cat,pig]

Person类中利用ConfigurationProperties(prefix=" ")引入配置类中的元素 但是注意Person类中的类的名字必须与application.yaml中一致

package com.qcby.model;import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;import java.util.Date;
import java.util.List;
import java.util.Map;@Component
@ConfigurationProperties(prefix = "person")
public class Person {private String name;private Integer age;private boolean boss;private Date birth;private Map<String,String> maps;private List<String> list;public Person() {}public Person(String name, Integer age, boolean boss, Date birth, Map<String, String> maps, List<String> list) {this.name = name;this.age = age;this.boss = boss;this.birth = birth;this.maps = maps;this.list = list;}public String getName() {return name;}public void setName(String name) {this.name = name;}public Integer getAge() {return age;}public void setAge(Integer age) {this.age = age;}public boolean isBoss() {return boss;}public void setBoss(boolean boss) {this.boss = boss;}public Date getBirth() {return birth;}public void setBirth(Date birth) {this.birth = birth;}public Map<String, String> getMaps() {return maps;}public void setMaps(Map<String, String> maps) {this.maps = maps;}public List<String> getList() {return list;}public void setList(List<String> list) {this.list = list;}@Overridepublic String toString() {return "Person{" +"name='" + name + '\'' +", age=" + age +", boss=" + boss +", birth=" + birth +", maps=" + maps +", list=" + list +'}';}
}

最终在Test包下进行测试

@RunWith(SpringRunner.class)  //声明为测试单元
@SpringBootTest  //读取配置
public class SpringBoot01ApplicationTests {@AutowiredPerson person;@Testpublic void Context(){System.out.println(person);}}

示例2(在properties文件中配置)

在application.properties中

person.email=lucky
person.hello=junit
person.lastName=jiangjiayi
person.age=12
person.boss=true
person.list=dog,cat
person.maps.key1=value1
person.maps.key2=value2
person.dog.name=${person.hello}  //${} 可以理解为Vue中的{{}} 调用的是上面的person.hello的值
person.dog.age=16

Person类

package com.qcby.model;import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;import javax.validation.constraints.Email;
import java.util.Date;
import java.util.List;
import java.util.Map;@Component
@ConfigurationProperties(prefix = "person")
public class Person {String email;String hello;String lastName;int age;boolean boss;List<String> list;Map<String,String>maps;Dog dog;public String getEmail() {return email;}public void setEmail(String email) {this.email = email;}public String getHello() {return hello;}public void setHello(String hello) {this.hello = hello;}public String getLastName() {return lastName;}public void setLastName(String lastName) {this.lastName = lastName;}public int getAge() {return age;}public void setAge(int age) {this.age = age;}public boolean isBoss() {return boss;}public void setBoss(boolean boss) {this.boss = boss;}public List<String> getList() {return list;}public void setList(List<String> list) {this.list = list;}public Map<String, String> getMaps() {return maps;}public void setMaps(Map<String, String> maps) {this.maps = maps;}public Dog getDog() {return dog;}public void setDog(Dog dog) {this.dog = dog;}@Overridepublic String toString() {return "Person{" +"email='" + email + '\'' +", hello='" + hello + '\'' +", lastName='" + lastName + '\'' +", age=" + age +", boss=" + boss +", list=" + list +", maps=" + maps +", dog=" + dog +'}';}
}

Dog类

package com.qcby.model;public class Dog {String name;int age;public Dog() {}public Dog(String name, int age) {this.name = name;this.age = age;}@Overridepublic String toString() {return "Dog{" +"name='" + name + '\'' +", age=" + age +'}';}public String getName() {return name;}public void setName(String name) {this.name = name;}public int getAge() {return age;}public void setAge(int age) {this.age = age;}
}

测试类

@RunWith(SpringRunner.class)  //声明为测试单元
@SpringBootTest  //读取配置
public class SpringBoot01ApplicationTests {@AutowiredPerson person;@Testpublic void Context(){System.out.println(person);}}

   如果不是标准的application.properties 是其他的Person类中需要用PropertySource来添加配置文件的路径

@ImportSource

导入Spring的配置文件,让配置文件里面的内容生效;Spring Boot里面没有Spring的配置文件,我们自己编写的配置文件,也不能自动识别;想让Spring的配置文件生效,加载进来;@ImportResource标注在一个配置类上

SpringBoot推荐给容器中添加组件的方式;推荐使用全注解的方式
1、配置类@Configuration------>Spring配置文件
2、使用@Bean给容器中添加组件,将方法的返回值添加到容器中 容器中这个组件的默认ID就是方法名

 生成随机数:

${random.value}、${random.int}、${random.long}
${random.int(10)}、${random.int[1024,65536]}

多profile文件

        通过spring:

                        profiles:

                                active:    来决定运行谁

配置文件加载位置的优先级

–file:./config/
–file:./
–classpath:/config/
–classpath:/

优先级由高到底,高优先级的配置会覆盖低优先级的配置; 

http://www.tj-hxxt.cn/news/5587.html

相关文章:

  • wordpress文章产品伊春seo
  • 网站信管局备案绍兴seo网站推广
  • 手表网站有哪个比较好2024疫情最新消息今天
  • 怎么用自己主机做网站、公司网站建设代理
  • 彭水县网站开发武汉百度推广seo
  • 宁波做网站优化如何在百度做免费推广产品
  • 网站百度权重百度认证服务平台
  • 能免费做网站收录情况有几种
  • 适合个人做的网站有哪些东西网络平台建设及运营方案
  • 初级网页设计夫唯seo
  • 旅游网站的建设与应用公司产品怎样网上推广
  • 重新做网站高端网站建设深圳
  • 网站慢用台服务器做跳板google 浏览器
  • 深圳网站制作排行榜兰州关键词快速上首页排名
  • 旅游网站建设策划书模板网站域名查询ip地址
  • 深圳做营销网站设计seo实战培训学校
  • 淄博网站关键词优化优化网站排名费用
  • 网站建设品牌好百度指数数据
  • ppt模板免费的网站seo描述是什么意思
  • 网站建设价格是哪些方面决定的腾讯广告推广平台入口
  • 公司网站建设管理意见房管局备案查询网站
  • 网站seo顾问搜索引擎大全全搜网
  • 网站建设网络推广最低价格网络营销类型有哪些
  • 做网站主要注意些什么免费制作网站的软件
  • 长沙岳麓区房价首页排名seo
  • 自己做网站不想买空间 自己电脑可以做服务器吗?南宁优化网站网络服务
  • 诚一网站推广网页怎么搜索关键词
  • 网站设计用什么软件实现360站长平台链接提交
  • 天河区进一步seo静态页源码
  • 哪里可以学ps软件网课站长工具seo综合查询网