Spring MVC 屬性檔案讀取注入到靜態字段

2021-08-02 15:38:10 字數 935 閱讀 7740

目錄(?)

[-]

servlet-contextxml

configproperties 示例屬性

configinfo 對應的配置bean使用

在專案中,有些引數需要配置到屬性檔案***.properties中,這樣做是為了維護方便,如果需要變動只需修改屬性檔案,不需要重新編譯專案就可以了,非常方便。

而為了使用起來方便,可以通過將屬性值注入到類的靜態欄位中(static),這樣就可以用classname.fieldname的方式來獲取了。

bean>

注意: 這裡需要配置spring自動掃瞄的包名,該包下包含了需要被註解的類configinfo

admin_id=1

default_password=888888

package com.jykj.demo.util;

import org.springframework.beans.factory.annotation.value;

import org.springframework.stereotype.component;

@component

public class configinfo ") public void setadmin_id(int admin_id) @value("$") public void setdefault_password(string default_password) }

注意: 這裡需要將自動生成setter的方法的修飾符static去掉,否則spring無法注入

在任何類中直接使用 configinfo.*** 即可方便引用,如 configinfo.default_password

SpringMVC讀取Excel檔案

使用註解接收檔案 requestparam value excel required true multipartfile file 其中value的值是上傳檔案的檔名 從file讀取輸入流 從file中獲取檔名 檔案大小以及輸入流等資訊 inputstream is file.getinputst...

屬性檔案讀取

執行結果如下 propertieskey eab036 propertiesvalue good005 propertieskey eab035 propertiesvalue good004 propertieskey eab034 propertiesvalue good003 properti...

vb 讀取檔案屬性

如果只是檢視大小 修改時間的話,可以直接使用vb內建函式 返回檔案位元組大小 filelen 檔案路徑 示例 private sub form load dim sout as string const sfile as string c windows notepad.exe sout 檔案路徑 ...