我想在Spring中有一個用於下載CSV的動態URL,例如, Bernhard_content_24Feb2017.csv
。更正式地說,這將是在URL中使用時間戳的Spring RequestMapping
{id}_content_{timestamp}.csv
像Me_content_1Jan2017.csv
或You_content_31Dec2017.csv
每個請求都應該去的方法在下面的代碼(getCsv(...))。請注意,我希望保留後綴.csv。用戶應該下載一個名爲Me_content_1Jan2017.csv
的文件。
所以我在春天嘗試這樣:
@RequestMapping("{id}_content_{timestamp}.csv")
public void getCsv(@PathVariable String id, @PathVariable String timestamp, HttpServletResponse response) {
response.getWriter().print(createCsv(id));
}
可惜,這是行不通的。
這將是什麼正確的語法?鑑於,這是可能的。
感謝,
伯恩哈德
UPDATE:
我去這個解決方案(重命名URL一點點,現在想Me_1Jan2017_content.csv
):
@RequestMapping("{idAndTimestamp}_content.csv")
public void getCsv(@PathVariable String idAndTimestamp, HttpServletResponse response) {
String id = idAndTimestamp.split("_")[0];
response.getWriter().print(createCsv(id));
}
爲什麼不把currentTime.millis()當作路徑,而不是像Bernhard_content_24Feb2017這樣的東西,並生成csv文件,你可以給任何名稱.....然後在爲客戶端進行strem後... – sitakant
可以你請提及時間戳和ID格式? – SachinSarawgi
ID和時間戳只是隨機字符串。所以ID也是[a-zA-Z0-9]。*和時間戳。順便說一句,我不使用時間戳。我只是想讓用戶下載一個帶有時間戳的文件:'Download CSV' – Bernie