1. 程式人生 > >SpringBoot通過配置檔案傳輸值到實體類

SpringBoot通過配置檔案傳輸值到實體類

1.建立一個配置檔案(appication.properties)項配置檔案加入以下:

upload.target=D:/data/repository/upload/
upload.target.folder.1=yyyy
upload.target.folder.2=MM

2.建立一個類: 1)在類上標註@Controller將此類納入容器 2)我們只需要在屬性上標註@Value(“加入自己定義在配置檔案中的屬性名”)

@Controller
public class UploadController {

	@Value("${upload.server}")
	private String picServer;
	
	@Value("${upload.target}")
	private String target;
	
	@Value("${upload.target.folder.1}")
	private String folder1;
	
	@Value("${upload.target.folder.2}")
	private String folder2;