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

建立网站的费用免费传奇网站域名哪里注册

建立网站的费用,免费传奇网站域名哪里注册,网站快照怎么做,温州网站建设有限公司目录 1. 使用Value和ConfigurationProperties2. 使用PropertySource创建Person.java写一个测试类 3. 使用ImportResourceStudent类创建beans.xml在主类中引入测试 其他心得 1. 使用Value和ConfigurationProperties 这里不加赘述了,前面我也发过,这里就放…

目录

  • 1. 使用@Value和@ConfigurationProperties
  • 2. 使用@PropertySource
      • 创建Person.java
      • 写一个测试类
  • 3. 使用@ImportResource
    • Student类
    • 创建beans.xml
    • 在主类中引入
    • 测试
  • 其他
  • 心得

1. 使用@Value和@ConfigurationProperties

这里不加赘述了,前面我也发过,这里就放个链接吧
@Value获取值和@ConfigurationProperties获取值用法及比较(springboot)

2. 使用@PropertySource

创建Person.java

package com.example.springbootdaily2.model;import org.springframework.format.annotation.DateTimeFormat;import java.util.Date;
import java.util.List;
import java.util.Map;@Component
@PropertySource(value = "classpath:person.properties")
// 这个是前缀的意思
@ConfigurationProperties(prefix = "person2")
public class PersonX {private String name;private Character sex;@DateTimeFormat(pattern = "YYYY-MM-SS")private Date birthday;private Integer age;private String address;private Map<String, Integer> maps;private List<String> lists;private Dog dog;public String getName() {return name;}public void setName(String name) {this.name = name;}public Character getSex() {return sex;}public void setSex(Character sex) {this.sex = sex;}public Date getBirthday() {return birthday;}public void setBirthday(Date birthday) {this.birthday = birthday;}public String getAddress() {return address;}public void setAddress(String address) {this.address = address;}public Dog getDog() {return dog;}public void setDog(Dog dog) {this.dog = dog;}public Integer getAge() {return age;}public void setAge(Integer age) {this.age = age;}public Map<String, Integer> getMaps() {return maps;}public void setMaps(Map<String, Integer> maps) {this.maps = maps;}public List<String> getLists() {return lists;}public void setLists(List<String> lists) {this.lists = lists;}@Overridepublic String toString() {return "Person{" +"name='" + name + '\'' +", sex=" + sex +", birthday=" + birthday +", age=" + age +", address='" + address + '\'' +", maps=" + maps +", lists=" + lists +", dog=" + dog +'}';}
}

创建person.properties

person2.name="李四"
person2.sex=男
person2.birthday=2022-02-07
person2.age=18
person2.maps.keys1=16
person2.maps.keys2=16
person2.lists=[12,24,57]
person2.address="保定廉耻"
person2.dog.name=${random.value}

写一个测试类

package com.example.springbootdaily;
import com.example.springbootdaily.model.Dog;
import com.example.springbootdaily.model.Person;
import com.example.springbootdaily.model.Person2;
import com.example.springbootdaily.model.PersonX;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;@RunWith(SpringRunner.class)
@SpringBootTest
public class SpringTest {@AutowiredPersonX personX;@Testpublic void print4(){System.out.println(personX);}
}

输出结果:

Person{name='"岳轩子"', sex=M, 
birthday=Sun Dec 26 00:00:00 CST 2021, age=18, 
address='"保定武汉"', maps={keys2=16, keys1=16}, lists=[[12, 24, 57]], 
dog=Dog{name='cdab390f55c9f8a6bbb420cd15607add'}}

注:如果显示乱码,设置文件编码为utf-8
在这里插入图片描述

3. 使用@ImportResource

Student类

package com.example.springbootdaily.model;public class Student {private String name;private Integer age;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;}@Overridepublic String toString() {return "Student{" +"name='" + name + '\'' +", age=" + age +'}';}
}

创建beans.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"><bean id="student" class="com.example.springbootdaily.model.Student"><property name="name" value="李四"/><property name="age" value="18"/></bean>
</beans>

在主类中引入

package com.example.springbootdaily;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ImportResource;@SpringBootApplication
@ImportResource(locations = "classpath:beans.xml")
public class SpringbootDailyApplication {public static void main(String[] args) {SpringApplication.run(SpringbootDailyApplication.class, args);}}

测试

package com.example.springbootdaily;import com.example.springbootdaily.model.*;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;@RunWith(SpringRunner.class)
@SpringBootTest
public class SpringTest {@AutowiredStudent student;@Testpublic void print5(){System.out.println(student);}
}

运行结果:

Student{name='李四', age=18}

其他

我们可以导入配置文件处理器,以后编写配置就有提示了
<!‐‐导入配置文件处理器,配置文件进行绑定就会有提示‐‐>
依赖:

<dependency><groupId>org.springframework.boot</groupId><artifactId>spring‐boot‐configuration‐processor</artifactId><optional>true</optional>
</dependency>

心得

平常还是要多多总结的。
在这里插入图片描述
谢谢大家支持!!!!

http://www.yayakq.cn/news/376224/

相关文章:

  • 产业园门户网站建设方案设计公司资质等级
  • 做二维码推送网站石家庄市建设局网站信息公开
  • 互联网站开发管理文档开发公司岗位设置
  • 主流科技类的网站都有哪些正规的公司网站建设
  • 深圳建设局网站注册结构师培训中国响应式网站
  • 网站的后期维护工作一般做什么东莞圆心科技网站开发
  • 盐城做网站的哪个公司好90平装修大约多少钱
  • 昆明网站建设团队潍坊专利申请
  • 长沙口碑好的做网站公司哪家好自媒体运营
  • 农业网站如何建设上海网站建设维护
  • 设计师网站pintset门户网站优点
  • 响应式网站模板的应用免费seo工具
  • 网站建设价格标准方案北京学生聚集
  • 做网站学不需要做后台管理系统一二三四视频社区在线
  • 上海做网站建设公司排名站长网站统计
  • 萍乡商城网站建设石桥铺网站建设公司
  • 杭州seo网络推广搜索引擎优化关键字
  • 调整百度对网站的最大天级抓取频次值一级a做网站免费
  • 定西市小企业网站建设网络公司推广软文
  • 有了域名和空间怎么做网站内容wordpress 头像打岔
  • 网站可以跟博客做互链吗wordpress打开文章
  • 做网站最好的网络公司免费网站建设的
  • 设计一个学院网站二级单位网站建设
  • 水网站模板营销型网站盈利模式
  • 微网站推广chrome官网
  • 枣强网站建设旅游网站建设电子商务的困惑
  • 织梦网站熊掌号改造怎么做vue新增页面
  • 化妆品营销型网站案例宠物网站页面设计ps
  • vs中的网站导航怎么做WordPress当前菜单高亮
  • 摄影师作品网站有哪些濮阳信息港网首页