满堂花醉三千客,一剑霜寒十四州。这篇文章主要讲述Spring Boot通过application.yml配置文件获取属性及类信息相关的知识,希望能为你提供帮助。
实体类信息br/>**@ConfigurationProperties(prefix="mycar")**
public class CarEntity {
public CarEntity() {
// TODO Auto-generated constructor stub
}private String carNo;
private String carName;
private String color;
private String carProductDate;
private double price;
public String getCarNo() {
return carNo;
}
public void setCarNo(String carNo) {
this.carNo = carNo;
}
public String getCarName() {
return carName;
}
public void setCarName(String carName) {
this.carName = carName;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
public String getCarProductDate() {
return carProductDate;
}
public void setCarProductDate(String carProductDate) {
this.carProductDate = carProductDate;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
@Override
public String toString() {
return "CarEntity [carNo=" + carNo + ", carName=" + carName + ", color=" + color + ", carProductDate="
+ carProductDate + ", price=" + price + "]";
}
}
【Spring Boot通过application.yml配置文件获取属性及类信息】application.yml文件属性配置信息
mycar:
carNo: 渝A88866
carName: 法拉利
color: Red
carProductDate: 2019-01-01
price: 500000br/>直接获取单个属性
@Value("${mycar.carNo}")
Controller获取属性类信息
@Autowired
private CarEntity carInfo;
@GetMapping(value="https://www.songbingjia.com/android/books/{userid}")
public String detail(@PathVariable Integer userid,Model m) {
m.addAttribute("bookid", userid);
UserEntity user = new UserEntity();
user.setId(userid);
user.setUsername("TOM JACK(王忠义)");
List<
UserEntity>
users = userMapper.getAllUser();
m.addAttribute("user", user);
**m.addAttribute("CarInfo", carInfo.toString());
**
return "bookshop";
}页面展示
<
p>
<
strong>
CarInfo:<
/strong>
<
span th:text="${CarInfo}">
<
/span>
<
/p>
推荐阅读
- Vue2.5开发去哪儿网App 首页开发
- android修改便携式热点的默认SSID名称
- android USB OTG功能如何打开及实现
- 在Python中使用PostgreSQL
- 循环学习率简介
- 电子表格入门教程
- 使用Tableau的电子表格
- SQL如何增强你的子查询()
- R中的数据帧