實體類信息br/>**@ConfigurationProperties(prefix="mycar")**
@Component
public class CarEntity {app
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 + "]"; }
}ide
application.yml文件屬性配置信息
mycar:
carNo: 渝A88866
carName: 法拉利
color: Red
carProductDate: 2019-01-01
price: 500000br/>直接獲取單個屬性
@Value("${mycar.carNo}")
private String carNo;this
Controller獲取屬性類信息 @Autowired private CarEntity carInfo; @GetMapping(value="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>