package com.whyc.service;
|
|
import com.whyc.util.MacUtil;
|
import org.springframework.stereotype.Service;
|
|
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletResponse;
|
import java.io.FileNotFoundException;
|
import java.io.IOException;
|
import java.io.OutputStream;
|
import java.io.UnsupportedEncodingException;
|
import java.net.URLEncoder;
|
import java.util.List;
|
|
@Service
|
public class MacService {
|
|
//获取mac
|
public void getMac(HttpServletRequest req, HttpServletResponse resp, int macNum) {
|
List<String> list = MacUtil.getMac(MacUtil.macStart, macNum);
|
//导出csv
|
String filename = "mac地址.csv";
|
try {
|
// 转码防止乱码
|
resp.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(filename, "utf-8"));
|
OutputStream out = resp.getOutputStream();
|
if (list != null) {
|
for (String mac : list) {
|
byte[] buffer = mac.getBytes();
|
out.write(buffer, 0, buffer.length);
|
out.write("\r\n".getBytes());
|
}
|
}
|
out.close();
|
} catch (FileNotFoundException | UnsupportedEncodingException e) {
|
e.printStackTrace();
|
} catch (IOException e) {
|
e.printStackTrace();
|
}
|
}
|
}
|